/* > To: Jim Gettys > Cc: gnome-list@gnome.org > Subject: Re: Milestones document > ----- > On Wed, 8 Dec 1999, Jim Gettys wrote: > > > For example, the next time you break library binary compatibility, you > > go through all data structures and sort the structure elements small to > > large, (often with subunits of information that ought to be local in a > > cache line) > > Small to large or large to small? (Or does it make a diff as long as it is > sorted?) Small to large: all C compilers in the world lay out memory in the order of declaration, and they keep data naturally aligned. This is universally true. While vital on a RISC, CISC's like an x86, while not causing a trap, will take a significant performance hit on unaligned data, so compilers have kept data naturally aligned by default for a long time (even a VAX took a significant performance hit if the data wasn't aligned, and it has gotten amazingrly worse as processors have gotten faster (and more RISC like internally on CISC machines). Example program length.c: */ #include typedef struct _foo { char character4; char *pointer; short integer; char *pointer2; char character2; } foostruct; typedef struct _foo2 { char character; char character2; short integer; char *pointer; char *pointer2; } foostruct2; main() { printf("size = %d, %d\n", sizeof(foostruct), sizeof(foostruct2)); exit(); } /* [jg@jg jg]$ ./length size = 20, 12 */