Say I have a simple C++ class that contains a variety of types with different sizes. To my understanding, types with identical sizes should be grouped together to maximize memory alignment. Assuming my goal is to maximize memory efficiency
What would be the best way of ordering types of differing sizes? In the example below, assume HeavyClass
is a large object. Am I correct in placing large objects at the end?
class MyClass {
int d_someInt;
int d_anotherInt;
long d_someLong;
HeavyClass d_heavyClass;
};
The usual things like cache locality, readability apply but all other being equal, I want to maximize alignment.