
12 Jan
2005
12 Jan
'05
8:45 a.m.
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."