gcc/libstdc++-v3/doc/html/manual/dynamic_memory.html
Jonathan Wakely 109a3af40f Makefile.am: Add missing file.
* doc/Makefile.am: Add missing file. Use generate.consistent.ids
	parameter for DocBook HTML generation.
	* doc/Makefile.in: Regenerate.
	* doc/doxygen/user.cfg.in: Unset DOT_FONTNAME.
	* doc/xml/faq.xml: Update content and improve formatting.
	* doc/xml/manual/abi.xml: Add stable ID attribute and fix links.
	* doc/xml/manual/allocator.xml: Add stable ID attribute.
	* doc/xml/manual/bitmap_allocator.xml: Likewise.
	* doc/xml/manual/build_hacking.xml: Likewise.
	* doc/xml/manual/codecvt.xml: Change URL.
	* doc/xml/manual/ctype.xml: Add stable ID attribute.
	* doc/xml/manual/debug_mode.xml: Likewise.
	* doc/xml/manual/documentation_hacking.xml: Likewise.
	* doc/xml/manual/evolution.xml: Likewise.
	* doc/xml/manual/extensions.xml: Likewise.
	* doc/xml/manual/locale.xml: Likewise.
	* doc/xml/manual/messages.xml: Make section id consistent, improve
	markup, change URL.
	* doc/xml/manual/parallel_mode.xml: Add stable ID attributes.
	* doc/xml/manual/profile_mode.xml: Likewise.
	* doc/xml/manual/shared_ptr.xml: Likewise. Also remove old info.
	* doc/xml/manual/status_cxx1998.xml: Add stable ID attributes.
	* doc/xml/manual/status_cxx2011.xml: Likewise.
	* doc/xml/manual/status_cxx2014.xml: Likewise.
	* doc/xml/manual/status_cxxtr1.xml: Likewise.
	* doc/xml/manual/status_cxxtr24733.xml: Likewise.
	* doc/xml/manual/using.xml: Likewise.
	* doc/html/*: Regenerate.

From-SVN: r211376
2014-06-09 15:47:17 +01:00

71 lines
4.7 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Dynamic Memory</title><meta name="generator" content="DocBook XSL-NS Stylesheets V1.78.1" /><meta name="keywords" content="ISO C++, library" /><meta name="keywords" content="ISO C++, runtime, library" /><link rel="home" href="../index.html" title="The GNU C++ Library" /><link rel="up" href="support.html" title="Chapter 4.  Support" /><link rel="prev" href="support.html" title="Chapter 4.  Support" /><link rel="next" href="termination.html" title="Termination" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Dynamic Memory</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="support.html">Prev</a> </td><th width="60%" align="center">Chapter 4. 
Support
</th><td width="20%" align="right"> <a accesskey="n" href="termination.html">Next</a></td></tr></table><hr /></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="std.support.memory"></a>Dynamic Memory</h2></div></div></div><p>
There are six flavors each of <code class="function">new</code> and
<code class="function">delete</code>, so make certain that you're using the right
ones. Here are quickie descriptions of <code class="function">new</code>:
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
single object form, throwing a
<code class="classname">bad_alloc</code> on errors; this is what most
people are used to using
</p></li><li class="listitem"><p>
Single object "nothrow" form, returning NULL on errors
</p></li><li class="listitem"><p>
Array <code class="function">new</code>, throwing
<code class="classname">bad_alloc</code> on errors
</p></li><li class="listitem"><p>
Array nothrow <code class="function">new</code>, returning
<code class="constant">NULL</code> on errors
</p></li><li class="listitem"><p>
Placement <code class="function">new</code>, which does nothing (like
it's supposed to)
</p></li><li class="listitem"><p>
Placement array <code class="function">new</code>, which also does
nothing
</p></li></ul></div><p>
They are distinguished by the parameters that you pass to them, like
any other overloaded function. The six flavors of <code class="function">delete</code>
are distinguished the same way, but none of them are allowed to throw
an exception under any circumstances anyhow. (They match up for
completeness' sake.)
</p><p>
Remember that it is perfectly okay to call <code class="function">delete</code> on a
NULL pointer! Nothing happens, by definition. That is not the
same thing as deleting a pointer twice.
</p><p>
By default, if one of the <span class="quote"><span class="quote">throwing <code class="function">new</code>s</span></span> can't
allocate the memory requested, it tosses an instance of a
<code class="classname">bad_alloc</code> exception (or, technically, some class derived
from it). You can change this by writing your own function (called a
new-handler) and then registering it with <code class="function">set_new_handler()</code>:
</p><pre class="programlisting">
typedef void (*PFV)(void);
static char* safety;
static PFV old_handler;
void my_new_handler ()
{
delete[] safety;
popup_window ("Dude, you are running low on heap memory. You"
" should, like, close some windows, or something."
" The next time you run out, we're gonna burn!");
set_new_handler (old_handler);
return;
}
int main ()
{
safety = new char[500000];
old_handler = set_new_handler (&amp;my_new_handler);
...
}
</pre><p>
<code class="classname">bad_alloc</code> is derived from the base <code class="classname">exception</code>
class defined in Sect1 19.
</p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="support.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="support.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="termination.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 4. 
Support
 </td><td width="20%" align="center"><a accesskey="h" href="../index.html">Home</a></td><td width="40%" align="right" valign="top"> Termination</td></tr></table></div></body></html>