From: Dave Handley (dave.handley_at_[hidden])
Date: 2005-01-20 10:29:48
> Dave Handley wrote:
> > My recommendations for things to look at include:
> > 1) Allocate using malloc as another creation policy
> I'm looking at Loki's library and thinking that it has a major bug.
> Doesn't his implementation have the same alignment problems that my
> original static allocator did? Wouldn't it be impossible to ensure that
> memory allocated by malloc was aligned properly?
Other posters have dealt with the fact that malloc and new don't have
alignment issues, but haven't explained why. Clearly alignment issues
exist when you have to have a particular variable (like an int)
sitting on a word boundary. This is an architecture limitation - it
usually depends on the bus size, since on a 32 bit bus, you would want
to get an int in a single fetch operation. An issue happens when you
don't know the type being allocated when you are actually doing the
allocation. Static memory is allocated by the linker, and the
standard does not guarantee any form of alignment, except that the
memory is alignment with the type being allocated. Malloc and New are
guaranteed to return memory that is aligned for an object of that size
(according to the standard). You can also have similar alignment
problems if you allocate memory on the stack.
Vandervoorde and Josuttis argue in their templates book that the
standard should be expanded to include an alignof operator that is
similar to the sizeof operator, but returns the aligned requirement.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk