On 10/14/2016 09:43 PM, Michael Marcin wrote:
Structure of arrays is a pretty well known pattern for improving memory density and enabling vectorization in high performance code. Also known as parallel arrays[1].
After hand-rolling yet another of these it occurred to me that you make a reasonable first implementation with a simple alias template.
template< typename... Ts > using soa = std::tuple< std::vector<Ts>... >;
example: soa
data; This is decent start but has several issues including: * nothing to preserve the invariant keeping the arrays the same length * missing coalesced interface for vector methods (size, reserve, etc) * no iterator * wasted storage for duplicated allocators, capacities, sizes * sizeof...(Ts) allocations could be a single large block
The work required to address these issues is not too great I think.
The purpose of item:
* sizeof...(Ts) allocations could be a single large block
is to just require 1 heap allocation instead of N, where N
is the number of vectors in soa