Assume the array size is SOME_CONSTANT. So I have this AOS (array of structs)
struct abc {
float a;
float b;
float c;
};
And I allocate memory for it by first defining the pointer and then allocating an AOS.
abc *foo = 0;
foo = (abc *)malloc(SOME_CONSTANT * sizeof(abc));
So this is fine. Now I want to make a Struct of arrays (SOA) like this:
struct abc {
float *a;
float *b;
float *c;
};
But I cannot seem to think of a way of allocating memory to the struct pointer abc *foo
The best I could come up was this:
struct abc {
float a[SOME_CONSTANT];
float b[SOME_CONSTANT];
float c[SOME_CONSTANT];
};
and then by doing:
abc *foo = 0;
foo = (abc *)malloc(sizeof(abc));
I am trying to see the performance difference between AOS and SOA with CUDA. Is there any other way I can allocate memory for an SOA (below)? Is using my above method a good practice?
struct abc {
float *a;
float *b;
float *c;
};