I got some objects with certain values, for example:
(1)
struct massPoint {
double pos;
double vel;
double acc;
} objects[LOTS];
or the same in arrays:
(2)
double pos[LOTS];
double vel[LOTS];
double acc[LOTS];
First question: Is it right if i call (1) padded data and (2) serial data?
Second question: If i do some operations which would only affect vel and acc and no pos, and i have LOTS of them, would (2) be preferable since it would be better in terms of caching performance because the pos[] dont have to be cached this way and in (1) it has to? Or do i not get the concept at all?
No idea for your first question
For your second question there is no general answer this depends on your architecture and of your usage pattern.
unpredictable) access and each double
makes up a cacheline and your data is correctly aligned both would be
equivalent in terms of caching.
superior on modern architectures if
you have streaming access to the
data, that is for which the compiler
/ runtime / hardware can easily
predict the future access and that have enough hardware registers for the all the pointers and the data
in cases you have only few registers,
since for the second the compiler
might need to keep track of your
current index in the three different arrays
so in summary it may depend on a lot of factors, but a tendencies that the second method would be preferable under many circumstances