data-oriented struct abstraction ?

short2cave via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat May 30 04:46:45 PDT 2015


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 = ...
}



More information about the Digitalmars-d-learn mailing list