Boost logo

Boost :

Subject: [boost] interest in structure of arrays container?
From: Michael Marcin (mike.marcin_at_[hidden])
Date: 2016-10-14 22:43:27


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<int,float,std::string> 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.

Potential names:
soa<Ts>
structure_of_arrays<Ts>
parallel_array<Ts>
struct_array<Ts>
parallel_vector<Ts>
struct_vector<Ts>

Does this already exist somewhere?
Does it seem useful?

[1]https://en.wikipedia.org/wiki/Parallel_array


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk