Re: Article on possible improvements to C++
* dragan:
Alf P. Steinbach wrote:
"Placement new"
is manually calling a constructor. It is "CONSTRUCTION" (a bad choice of
terminology, but so it is in C++).
It sounds as if you degree with my description. In that case, sorry but whatever
you mean is incorrect. Placement new does exactly the same as non-placement new:
calling an allocation function with specified allocation function arguments, and
if that succeeds, calling a constructor with specified constructor arguments.
For example,
#include <stdio.h>
struct S
{
void* operator new( size_t const size, char const* const blah )
{
printf( "allocation function called, arg = \"%s\"\n", blah );
return ::operator new( size );
}
S( int const whatever )
{
printf( "constructor called, arg = %d\n", whatever );
}
};
int main()
{
S* const p = new( "Get it?" ) S( 42 );
}
was probably originally referring to the ability to
specify some existing storage, a placement of the object, but in the
standard's terminology "placement" refers to any allocation function
with extra arguments, or new expression supplying such arguments.
Technically a placement new expression does the same as a
non-placement new expression.
Also, there's no big difference for a global new operator.
Cheers & hth.,
- Alf