[Blog post] Why and when you should use SoA

maik klein via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Sat Mar 26 13:55:17 PDT 2016


On Friday, 25 March 2016 at 21:41:13 UTC, ZombineDev wrote:
> On Friday, 25 March 2016 at 21:22:51 UTC, ZombineDev wrote:
>> On Friday, 25 March 2016 at 01:07:16 UTC, maik klein wrote:
>>> Link to the blog post: https://maikklein.github.io/post/soa-d/
>>> Link to the reddit discussion: 
>>> https://www.reddit.com/r/programming/comments/4buivf/why_and_when_you_should_use_soa/
>>
>> Nice article. BTW, I would abstract the container concept from 
>> the SOA implementation, in order to allow for pluggable 
>> containers which probably simplify the code a little bit.
>
> Another note - you can further simplify the implementation by 
> using Fields!T and .tupleof. For example:
>
> void insertBack(Fields!T fields)
> // ....
>
> void insertBack(T t)
> {
>     if(length == size) grow;
>
>     foreach(idx, field; t.tupleof)
>         containers[idx][length] = field;
>
>     length++;
> }

Thanks, yes that is simpler.

But I am not sure that I want to have pluggable containers in 
SOA, mostly because every field would have overhead from the 
container.

For example array has size, length etc as overhead, but it is 
also not that much and probably won't matter anyway.

But I also thought about it, maybe sometimes I want to use a map 
instead of an array for some fields. So I need to have a way of 
telling which field should get which container.

Maybe something like this:

SOA!(Foo, Array, HashMap, DList);

The current implementation is mostly for experimentation.


More information about the Digitalmars-d-announce mailing list