On Mon, 13 Oct 2008, John Peterson wrote: > Okay. For some reason I thought tiny structs like that might get > padded out to a 4 or 8-byte boundary in memory.
The reason for padding is to avoid misaligned data in memory. So if you had a struct containing a char and a short, for example, a padding byte after the char would make sure that the 2-byte short was aligned on a 2-byte boundary. Make it a 4-byte int instead and 3 padding bytes are needed. But if there's nothing more than 1 byte long in your struct, there's nothing to misalign. Any padding that gets needed will be added to whatever other structs this one becomes a part of - so a complex<char> followed by an int will probably require 2 bytes in between. Like I said, though, I'm not sure how much of this is set in stone by a standard, how much is common sense that every compiler follows, and how much is just a tradition that's waiting to bite us when a compiler does something different. Try to pin this stuff down and you end up wading in non-standard "#pragma" directives. For a array-of-structs-of-2-T and an array-of-T, though, I think we're safe. --- Roy ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Libmesh-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/libmesh-users
