data-oriented struct abstraction ?

Rikki Cattermole via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat May 30 05:34:16 PDT 2015


On 30/05/2015 11:46 p.m., short2cave wrote:
> Consider this struct:
>
> ---
> Foo
> {
>      uint a,b,c;
>      float d,e,f;
> }
> ---
>
> in a collection:
>
> ---
> Foo[] foos;
> ---
>
> Looping a particular member is not cache friendly
>
> ---
> foreach(foo;foos){/*foo.a = ...*/}
> ---
>
> but to write clear, understable, structured code, the struct is necessary.
>
> So, is it possible to imagine an abstraction such as
>
> ---
> FooData
> {
>      uint[] a,b,c;
>      float[] d,e,f;
>      Foo[] items(){}
> }
> ---
>
> that would allow to loop over the data in a cache-friendly way ?
> You think that an item as the member but they are actually stored using
> another memory layout ?
>
> A template for this would be particularly usefull:
>
> template DataFriendlyStruct(T) if (is(T==struct) && isPOD!T)
> {
>     alias DataFriendlyStruct = ...
> }

What exactly are you doing that such a micro optimization is necessary?



More information about the Digitalmars-d-learn mailing list