I am learning about memory alignment. I think I understand the concept and I just want to make sure if I understand the practice correctly with an example.
I have 2 classes like below
class Base {
int64_t a;
int64_t b;
int64_t c;
int64_t d;
virtual void method();
}
class A: public Base {
// 8 bytes virtual pointer
// 32 bytes Base object
// 16 bytes C struct
C data;
void method() override;
}
Right now class A sits at 56 bytes. To make A memory aligned when using it in an array, I am thinking it needs 8 more padding bytes because 64 is divisible by 32, which is the largest member of the class. My first question is that Im not sure if I need it, cause in reality Base's member is actually 8 byte aligned. And even if I do need it, should I put the 8 bytes padding before member "data" or after "data". I'm thinking before "data" because C is 16 bytes, and putting it before "data" would mean that "data" starts at byte 48, divisible by 16.
Thanks in advance.
Edit: I forgot to include this, but A actually overrides some virtual methods from Base. That's where the virtual table pointer comes from