🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Tightly packed float/double ?

Started by
11 comments, last by Green_Baron 4 years, 11 months ago

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

Advertisement

Cool, thanks for hints @Bregma, appreciated mucho.

In an attempt to be funny i blame the IDEs urge to patronize ?  but of course i should have seen that.

 

This topic is closed to new replies.

Advertisement