The Data-Oriented way of organizing data. You have a single structure that contains multiple parallel arrays.
struct ParticleSystem {
std::vector<float> x;
std::vector<float> y;
std::vector<float> z;
std::vector<float> velocity;
std::vector<int> id;
};- Layout:
[x, x, x...][y, y, y...][z, z, z...] - Pros: Excellent for SIMD. When calculating the sum of
x, the CPU loads a cache line full of nothing butxvalues. This allows the hardware to pack multiple floats into a single 256-bit or 512-bit register (AVX/AVX-512) and process them in one clock cycle. - Cons: Lower spatial locality for operations involving a single entity. Accessing all properties of “Particle 5” requires jumping to five different memory locations.