Jump to content
  • Advertisement
Sign in to follow this  
Alundra

Always align memory in array class ?

Recommended Posts

Posted (edited)

Hi,
I always align memory in my custom array class but I would opinion.
Is it really better or not because that ends to have empty memory used too.
What is your opinion about it ?
Thank you

Edited by Alundra

Share this post


Link to post
Share on other sites
Advertisement

Alignment is important for many things. Most CPUs cannot access unaligned memory. If you want to save on the padding, try rearranging stuff inside of your elements or consider going from Array of Structures to a Structure of Arrays, i.e. instead of having

struct MyStruct {
  uint32_t foo;
  uint16_t bar;
};

MyStruct array[100]; // 200 bytes wasted

To something like

struct MyData {
  uint32_t foo[100];
  uint16_t bar[100];
};

MyData data; // Nothing wasted.

 

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
Sign in to follow this  

  • 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!