Members - Reputation: 1315
Posted 12 September 2004 - 01:32 PM
there are ways to turn off the padding in your code, just google for it if you truly care.
Members - Reputation: 2076
Posted 12 September 2004 - 01:35 PM
Members - Reputation: 2012
Posted 12 September 2004 - 01:46 PM
Now, assuming the compiler pads to 4 bytes, and that an int is 4 bytes and a char is 1, that structure will be 12 bytes long. The first int takes up 4 bytes, and then the 5th byte is taken up by ch1. The compiler then puts 3 bytes of padding in after that, so that n2 is aligned to a 4 byte boundary. That should (in theory) make it faster to access n2.
However, if you're reading and writing this structure to a file, you probably don't want padding, since you expect to read 9 bytes - not 12. So you would disable padding for this structure.
Members - Reputation: 97
Posted 19 February 2013 - 01:38 AM
structure padding matters most when alignment matters, which helps in potential performance and avoids any possible bus errors, please refer
Moderators - Reputation: 38112
Posted 19 February 2013 - 02:12 AM
Check out my book, Game Development with Unity, aimed at beginners who want to build fun games fast.
Also check out my personal website at bryanwagstaff.com, where I occasionally write about assorted stuff.