Content deleted Content added
m Date maintenance tags and general fixes: build X1 |
m Date maintenance tags and general fixes: build 561: |
||
Line 1:
In the [[C++]] [[programming language]], '''placement syntax''' allows programmers to explicitly specify the [[memory management]] of individual objects — i.e. their "placement" in [[memory (computing)|memory]]. Normally, when an object is created dynamically, an allocation function is invoked in such a way that it will both allocate memory for the object, and [[Constructor (object-oriented programming)|initialize]] the object within the newly allocated memory.<!--5.3.5--> The placement syntax allows the programmer to supply additional arguments to the allocation function. A common use is to supply a [[pointer (computing)|pointer]] to a suitable region of storage where the object can be initialized, thus separating memory allocation from object construction.{{
The "placement" versions of the <code>[[new (C++)|new]]</code> and <code>[[delete (C++)|delete]]</code> operators and functions are known as placement <code>new</code> and placement <code>delete</code>.<ref name=McCluskey2000 /> A <code>new</code> ''expression'', placement or otherwise, calls a <code>new</code> ''function'', also known as an allocator function, whose name is <code>operator new</code>. Similarly, a <code>delete</code> ''expression'' calls a <code>delete</code> ''function'', also known as a deallocator function, whose name is <code>operator delete</code>.<ref name=Lischner2003 /><ref name=Lippman1997 />
Line 6:
== History ==
In earlier versions of C++ there was no such thing as ''placement new''; instead, developers used explicit assignment to ''this'' within constructors to achieve similar effect.<ref name=Stroustrup1991 /> This practice has been deprecated and abolished later, and third edition of ''[[The C++ Programming Language]]'' doesn't mention this technique. Support for ''placement new'' operator has been added to compilers circa 1995.{{
== Expressions ==
Line 69:
</source>
Default placement does not require the inclusion of the Standard C++ library header <code><new></code> in the source code of a C++ program.<ref name=Lischner2003 /> However, g++ version 4.0 still requires the use of this header (this might be true of other versions of the compiler or other compilers too.){{
There are various uses for default placement.
Line 250:
<ref name=SeedCooper2001>{{harvnb|Seed|Cooper|2001|pp=435–436}}</ref>
<ref name=SolterKleper2005>{{harvnb|Solter|Kleper|2005|pp=458–461}}</ref>
<ref name=Stroustrup1991>{{harvnb|Stroustrup|1991|pp=}}{{
<ref name=Stroustrup1994>{{harvnb|Stroustrup|1994|pp=214}}</ref>
<ref name=Stroustrup1997b>{{harvnb|Stroustrup|1997|pp=255–256,576}}</ref>
|