Jump to content
  • Advertisement

C++ Tightly packed float/double ?

Recommended Posts

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.



Share this post

Link to post
Share on other sites

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.


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!