Members - Reputation: 1275
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.
Staff Emeritus - Reputation: 1670
Posted 12 September 2004 - 01:35 PM
Members - Reputation: 1955
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