and is quite influential in accesses efficiency |
It will be stored in memory the order that it is declared. This will sometimes mean that a different ordering can be stored more compactly, depending on alignment necessities.
The way the variables are laid out can affect cache efficiency. Most consumer machines have around a 64-byte cache line. So if, for example, you have an array of objects, and each object has a thousand different member variables, but you have a loop that only needs to operate on one of those members in the array, then you will get a cache miss
every single time you access the next element in the array.
But if you had a dedicated array that only had that one particular member variable packed into it, and let's say that member variable is 4 bytes large, that means you can go through 64/4 = 16 elements at a time before hitting the next cache miss, which can be a notable performance increase (as always, MEASURE, don't assume).