Nice, that you found the solution. The central question for me was, why the size of your vector class was bigger than 16 bytes. With the extra 8 bytes of the vtable pointer, you get the 24 bytes. It also explains the class alignment of 8 instead of 4.
4 minutes ago, Bregma said:The language guarantees the elements of an array are laid out in consecutive memory without any padding. You can rely on that.
Since it also guarantees you, that alignment requirements of the element type are met, I was curious what happens if I create a struct that has a higher alignment requirement than its expected size:
struct alignas(16) A
{
float a;
};
The outcome was, that the compiler adds padding to the struct itself. So A had a size of 16 instead of 4. Therefore, an array could be stored contiguously without any "extra/external" padding while the alignment requirements are also met.
Greetings