This article was in cprogramming.com. When using sizeof() I have never noticed such a feature.The size of this class is, 24 bytes. Even though char c will consume only 1 byte, 4 bytes will be allocated for it, and the remaining 3 bytes will be wasted (holes). This is because the next member is an int, which takes 4 bytes. If we don.t go to next 4th byte for storing this integer member, the memory access/modify cycle for this integer will be 2 read cycle. So the compiler will do this for us, unless we specify some byte padding/packing.Code:class C { char c; int int1; int int2; int i; long l; short s; };
If this wastes memmory, Why is this done?
and if this size thingi is compiler specific, how can one ensure poratability of the prgram?
More over I have never seen this stuff in any of the few books I've read.
Can some one please explain this???



LinkBack URL
About LinkBacks


