On Sat, Jun 16, 2007 at 12:08:40PM -0700, michael.a wrote: > As for "placement new", from what I can find, it is unsafe to use with any > memory that isn't part of the heap.
You do have to concern yourself with alignment. But often an allocator that hands out memory that is filled in by placement new doesn't use the heap at all. Using a union for the storage that's filled by the placement new call is one way to assure correct alignment. > As for the discussion of unions, placement new is way too much overhead. Placement new has *no* overhead, it pretty much invokes the constructor directly, and if the constructor is inline, there isn't even a function call. I'm sorry that you are not open to learning about it, and that you seem to believe many things about it that are not true. It does require you to worry about lower-level details, like assuring correct alignment. > Sometimes extensions just have to be quick and dirty. Microsoft is a major > influence. The facilities should be there to match MS whenever within > reason... as well as should be ever present warnings not to abuse such > facilities. Not if you want the gcc developers to accept it. Accepting the extension is a commitment to maintain it pretty much indefinitely. Also, if the gcc extension doesn't do everything the Microsoft extension does, your code might not work even if it compiles: it might leak memory or crash if the constructor/destructor behavior differs. But I'm puzzled that you'd rather try to hack the compiler than investigate a way to make your program portable C++. Or do you think you can talk others into hacking the compiler for you? I doubt that it will work.