Topic: redefining new - object alignment problems?


Author: msample@cs.ubc.ca (Mike Sample)
Date: 4 Nov 1993 21:34:11 -0800
Raw View
Howdy,

Is there a potential problem with programmer defined new/delete with
respect to object alignment? (other than just word alignment)

from section 5.4 of the reference manual in Stroustrup 2nd ed:

"Aggregates are aligned on the strictest boundary required by any of
their constituents."


Ok, let's say I define operator new & delete in a base class and that
this new operator's implementation uses its own chunk of memory (and
ensures word alignment on the pointers to memory that it returns).

Now let's say I derive a class from this base that has a double or long
double and that the hardware requires quadword alignment or some other
alignment larger than word alignment for doubles.

Is my call to "new derivedClass" going to return an pointer to an
object that will have problems when it tries to do operations on the
double value it contains?  or other problems?

Am I out to lunch here? Or is there a way to get the alignment
requirements of an object?

Thanks for any comments on this.

------------------------------------------------/\------------------
Mike Sample <msample@cs.ubc.ca>            /\  /vv\/^\
Dept. of Computer Science                 /  \/    \  \_______
University of British Columbia, Canada   / climb/tele/jam on! \