Placement syntax: Difference between revisions

Content deleted Content added
Monkbot (talk | contribs)
m Task 18 (cosmetic): eval 23 templates: del empty params (3×); hyphenate params (14×); del |ref=harv (15×);
Line 230:
</syntaxhighlight>
 
This is why the ''pointer placement'' delete functions are defined as no-operations by the Standard C++ library. Since the pointer placement new functions do not allocate any storage, there is no storage to <ref name=":0">{{Cite journal|last=Kundu|first=Ashish|last2=Bertino|first2=Elisa|date=June 2011|title=A New Class of Buffer Overflow Attacks|url=https://ieeexplore.ieee.org/document/5961725|journal=2011 31st International Conference on Distributed Computing Systems|volume=|pages=730–739|doi=10.1109/ICDCS.2011.63|via=IEEE}}</ref>be deallocated in the event of the object's constructor throwing an exception.<ref name=SolterKleper2005 />
 
If no matching placement delete function exists, no deallocation function is called in the event of an exception being thrown by a constructor within a placement <code>new</code> expression. There are also some (older) C++ implementations that do not support placement delete (which, like the exception-throwing allocator functions, were an addition made to C++ when it was standardized) at all. In both such situations, an exception being thrown by a constructor when allocating using a custom allocator will result in a memory leak. (In the case of the older C++ implementations, a memory leak will also occur with ''non-''placement <code>new</code> expressions.)<ref name=Meyers1998 /><ref name=Anderson1998b />
Line 259:
== References ==
{{refbegin|1}}
* {{cite book|ref=harv|title=Navigating C++ and Object-oriented Design|first=Gail|last=Anderson|chapter=Object Storage Management|publisher=Prentice Hall|year=1998a|isbn=9780135327487}}
* {{cite book|ref=harv|title=Navigating C++ and Object-oriented Design|first=Gail|last=Anderson|chapter=Exception Handling|publisher=Prentice Hall|year=1998b|isbn=9780135327487}}
* {{cite web|ref=harv|url=http://www.desy.de/user/projects/C++/g++faq/placement_new_syntax.html|title=3.4. g++ won't accept the placement new syntax.|date=1997-05-12|first=Joe|last=Buck|work=Frequently asked questions about the GNU C++ compiler|accessdateaccess-date=2008-11-26}}
* {{cite book|ref=harv|title=C++ Gotchas|first=Stephen C.|last=Dewhurst|chapter=Gotcha #62: Replacing Global New and Delete|chapterurlchapter-url=http://informit.com/articles/article.aspx?p=30642&seqNum=3|publisher=[[Addison-Wesley]]|year=2003|isbn=978-0-321-12518-7}}
* {{cite book|ref=harv|title=C++ in a Nutshell|first=Ray|last=Lischner|publisher=O'Reilly|year=2003|isbn=9780596002985}}
* {{cite book|ref=harv|title=C++ Gems|first=Stanley B.|last=Lippman|authorlinkauthor-link= Stanley B. Lippman |publisher=Cambridge University Press|year=1997|isbn=9780135705810}}
* {{cite book|ref=harv|title=C++ Pocket Reference|first=Kyle|last=Loudon|publisher=O'Reilly|year=2003 |isbn=9780596004965}}
* {{cite web|ref=CITEREFMcCluskey2000|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|accessdateaccess-date=2008-11-26|url-status=dead|archiveurlarchive-url=https://web.archive.org/web/20060418093041/http://www.glenmccl.com/nd_cmp.htm|archivedatearchive-date=2006-04-18}}
* {{cite news|ref=harv|date=1998-04-01|first=Scott|last=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}}
* {{cite book|ref=harv|title=An Introduction to Object-oriented Programming in C++|first1=Graham M.|last1=Seed|first2=Barry J.|last2=Cooper|publisher=Springer|year=2001|isbn=1-85233-450-9|edition=Second}}
* {{cite book|ref=harv|title=Professional C++|first1=Nicholas|last1=Solter|first2=Scott|last2=Kleper|publisher=Wiley|year=2005|isbn=9780764574849}}
* {{cite book|ref=harv|title=The C++ Programming Language|edition=2nd|first=Bjarne|last=Stroustrup|authorlinkauthor-link=Bjarne Stroustrup|isbn=978-0-201-53992-9|date=July 1991|url-access=registration|url=https://archive.org/details/cprogramminglang00stro}}
* {{cite book|ref=harv|last=Stroustrup|first=Bjarne|authorlinkauthor-link=Bjarne Stroustrup|title=Design and Evolution of C++|publisher=[[Addison-Wesley]]|isbn=978-0-201-54330-8|year=1994|chapter=Memory Management}}
* {{cite book|ref=harv|last=Stroustrup|first=Bjarne|authorlinkauthor-link=Bjarne Stroustrup|title=The C++ Programming Language|publisher=[[Addison-Wesley]]|edition=3rd|isbn=978-0-201-88954-3|year=1997|url-access=registration|url=https://archive.org/details/cprogramminglang00stro_0}}
* {{cite book|ref=harv|title=Multi-paradigm Programming Using C++|first=Dirk|last=Vermeir|publisher=Springer|year=2001|isbn=9781852334833}}
* {{cite web|ref=harv|title=A Cross-Platform Memory Leak Detector|date=2007-12-31|first=Wu|last=Yongwei|accessdateaccess-date=2008-11-26|work=Wu Yongwei's Programming Page|url=http://wyw.dcweb.cn/leakage.htm}}
{{refend}}
 
== Further reading ==
* {{cite book|last=Franek|first=Frantisek|title=Memory as a Programming Concept in C and C++|publisher=[[Cambridge University Press]]|isbn=978-0-521-52043-0|year=2004}}
* {{cite web|title=11.10: What is "placement new" and why would I use it?|url=http://parashift.com./c++-faq-lite/dtors.html#faq-11.10|work=C++ FAQ Lite|date=2006-09-25|first=Marshall|last=Cline|accessdateaccess-date=2008-11-26}}
* {{cite web|url=http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/topic/com.ibm.vacpp6m.doc/language/ref/clrc05cplr199.htm|title=C++ new Operator|work=IBM's Mac OS X compilers|year=2003|publisher=[[IBM]]|accessdateaccess-date=2008-11-27}}
* {{cite web|url=http://msdn.microsoft.com/en-us/library/t48aek43.aspx|work=[[MSDN]]|title=The operator new Function|publisher=[[Microsoft]]|access-date=|accessdate=2008-11-27}}
* {{cite web|url=http://msdn.microsoft.com/en-us/library/kewsb8ba.aspx|work=[[MSDN]]|title=new Operator (C++)|publisher=[[Microsoft]]|access-date=|accessdate=2008-11-27}}
 
{{DEFAULTSORT:Placement Syntax}}