Jump to content
  • Advertisement
Sign in to follow this  
ronnybrendel

does system use/lose the space?

This topic is 4464 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

if i declare a class like this class X{ uint8_t i; } sizeof(X) = 4byte / 8byte(x64) (because of wordalignment afaik) does the system really "lose" this 3/7 byte ? in my case its pretty important because such a class will be used pretty often i mean ... 7 byte can be pretty much space, when you use this class a couple of million times [Edited by - ronnybrendel on April 28, 2006 10:29:59 AM]

Share this post


Link to post
Share on other sites
Advertisement
Yup, the pad bytes are "lost" in that they are allocated and consume storage. Some particularly nasty hacks involve storing "secret" data in these pad bytes, but that's really a bad thing to be doing.

1,000,000 instances of an 8-byte class is 8,000,000 bytes. 8,000,000 bytes is on the order of 7.5ish MB of peak memory usage (assuming all one million instances are allocated at a time). If you are that strapped for memory, may I direct you to your local Best Buy?

Yes, you can remove the padding using compiler-specific #pragmas or other extensions. In Visual Studio you'll want to look up #pragma pack. However you should be aware that while you may be reducing size, you're sacrificing other things, such as speed, potentially (you may end up paying for misaligned data access).

Unless you've profiled and really discovered that those pad bytes are really, really killing you, this is not something to concern yourself with.

Share this post


Link to post
Share on other sites
thanx for the help :)

edit: we use a treestructure for displaying tracedata (such as function-calls, ipc-messages, counter, ...) and we are currently trying to reduce RAM usage in order to load bigger traces .... some traces have more than 50mio functioncalls ... so its important to save every single byte :X ... my task at the moment is to create an efficient structure ... ( important is the x64-stuff, because of "newer" HPC use x64)

Share this post


Link to post
Share on other sites
Quote:
Original post by jpetrie
Yes, you can remove the padding using compiler-specific #pragmas or other extensions. In Visual Studio you'll want to look up #pragma pack. However you should be aware that while you may be reducing size, you're sacrificing other things, such as speed, potentially (you may end up paying for misaligned data access).


Even with #pragma pack, each instance of class X will still be word-aligned, so you'll still lose the pad bytes.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!