|
Boost : |
From: Darryl Green (darryl.green_at_[hidden])
Date: 2005-01-12 03:45:36
Noah Stein <noah <at> acm.org> writes:
> > On Behalf Of Jason Hise
> > T * p = reinterpret_cast < T * > ( new char [ sizeof ( T ) ] );
>
> Your Create() function in AllocateUsingNew isn't guaranteed to work for all
> classes. The type of the singleton class might have alignment restrictions.
> char has no alignment restrictions; therefore, the program may crash when
> trying to initialize the singleton. I believe boost::aligned_storage is
> your friend in this situation.
Are you sure there is a problem here? Doesn't 5.3.4/10 allow this. The
explanatory note reads in part:
"...this constraint on array allocation overhead permits the common idiom of
allocating character arrays into which objects of other types will later be
placed."
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk