Subj : Re: Performance impact of disaligned structures To : comp.programming From : mschaef Date : Tue Oct 04 2005 10:22 am In article , Gioele Barabucci wrote: >How much "worse" is this structure > >struct { > uint64 length; > uint32 id; > uint64 *next; /* this is 32 bits aligned */ > uint64 data[256]; /* this starts on the 32 bits boundary */ >} > >compared to this other > >struct { > uint64 length; > uint32 id; > uint32 padding; > uint64 *next; /* now this is 64 bits aligned */ > uint64 data[256]; /* and this starts on the 64 bits boundary */ >} Let the compiler handle structure alignment, and override if necessary. Explicit padding is typically used when trying to match in-memory structure layouts with on-disk/network layouts. Even then, that doesn't account for differing byte orders, etc. >How (and how much) will the different layout affect run time speed? My >targets are x86 and ppc32 on the 32 bits side and x86_64 and POWER >(ppc64) on the 64 bits side. Measure it and find out. You're asking a very specific question that's impacted by lots of implementation details in your hardware's design. This is the kind of thing you ought to carefully benchmark, if you really are that concerned about it. My suggestion is to use the compiler defaults until you have a performance problem, measure to find out what the problem is, and then optimize there. -Mike -- http://www.mschaef.com .