Placement syntax: Difference between revisions

Content deleted Content added
m Unlinking full-dates. Details here. Codes: ISO1(×14)
attempt to make more accessible
Line 1:
In the [[C++]] [[programming language]], '''placement syntax''' allows programmers to explicitly specify the [[memory management]] of individual objects&nbsp;— i.e. their "placement" in [[memory (computing)|memory]]. Normally, Thewhen "placement"an versionsobject ofis created dynamically, the <code>allocation function is invoked in such a way that it will both allocate memory for the object, and [[newConstructor (C++object-oriented programming)|newinitialize]]</code> andthe object within the newly allocated memory.<code!--5.3.5--> The placement syntax allows the programmer to supply additional arguments to the allocation function. A common use is to supply a [[deletepointer (C++computing)|deletepointer]]</code> operatorsto anda functionssuitable areregion knownof asstorage placementwhere <code>new</code>the andobject placementcan <code>delete</code>.<refbe name=McCluskey1>{{citeinitialized, web|url=http://glenmccl.com./nd_cmp.htm|title=Placementthus New/Delete|publisher=Glenseparating McCluskeymemory &amp;allocation Associatesfrom LLC|work=C++object Languageconstruction. and Library|date=2000-06-26|accessdate=2008-11-26}}</ref>
 
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=McCluskey1>{{cite web|url=http://glenmccl.com./nd_cmp.htm|title=Placement New/Delete|publisher=Glen McCluskey &amp; Associates LLC|work=C++ Language and Library|date=2000-06-26|accessdate=2008-11-26}}</ref> 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=Lischner1 /><ref name=Lippman1 />
 
Any <code>new</code> expression that uses the placement syntax is a placement <code>new</code> expression, and any <code>operator new</code> or <code>operator delete</code> function that takes more than the mandatory first parameter (<source lang="cpp" enclose=none>size_t</source> and <source lang="cpp" enclose=none>void *</source>, respectively) is a placement new or placement delete function.<ref name=DDJMeyers1998>{{cite news|date=1998-04-01|author=Scott Meyers|title=Placement new and placement delete|url=http://ddj.com//showArticle.jhtml?documentID=cuj9804meyers&pgno=2|work=[[Dr. Dobb's Journal]]|publisher=United Business Media LLC}}</ref>