Subj : Re: Performance impact of disaligned structures To : comp.programming From : mwojcik Date : Fri Oct 07 2005 05:03 pm In article <87u0fw2j0c.fsf@benpfaff.org>, Ben Pfaff writes: > mschaef@fnord.io.com (MSCHAEF.COM) writes: > > > Does malloc generally make any guarantees about alignment, or is this a > > platform-specific thing? > > From C99: > > > The pointer returned if the allocation succeeds is suitably > > aligned so that it may be assigned to a pointer to any type > > of object and then used to access such an object or an array > > of such objects in the space allocated (until the space is > > explicitly deallocated). Of course, exactly what counts as "access" is implementation- dependent, and there are other quality-of-implementation issues. There was a DDJ article years ago that noted that the then-current MSVC malloc returned four-byte-aligned areas, and while those worked for all types, they caused a performance hit for doubles if the area wasn't also eight-byte-aligned. Since this thread was discussing Altivec, which has stricter align- ment requirements than conventional operations for the CPU, it's worth noting that a conforming C implementation that does not use Altivec itself need not supply areas aligned for Altivec from its malloc. In other words, C only guarantees that its alignment will suit itself. -- Michael Wojcik michael.wojcik@microfocus.com How can I sing with love in my bosom? Unclean, immature and unseasonable salmon. -- Basil Bunting .