X-Git-Url: https://oss.titaniummirror.com/gitweb?a=blobdiff_plain;f=libstdc%2B%2B-v3%2Fdoc%2Fhtml%2Fmanual%2Fdynamic_memory.html;fp=libstdc%2B%2B-v3%2Fdoc%2Fhtml%2Fmanual%2Fdynamic_memory.html;h=2a3d1368bd7b9fad8b6dfb526b3979908a5f6b10;hb=6fed43773c9b0ce596dca5686f37ac3fc0fa11c0;hp=0000000000000000000000000000000000000000;hpb=27b11d56b743098deb193d510b337ba22dc52e5c;p=msp430-gcc.git diff --git a/libstdc++-v3/doc/html/manual/dynamic_memory.html b/libstdc++-v3/doc/html/manual/dynamic_memory.html new file mode 100644 index 00000000..2a3d1368 --- /dev/null +++ b/libstdc++-v3/doc/html/manual/dynamic_memory.html @@ -0,0 +1,69 @@ + + +
+ There are six flavors each of new
and
+ delete
, so make certain that you're using the right
+ ones. Here are quickie descriptions of new
:
+
+ single object form, throwing a
+ bad_alloc
on errors; this is what most
+ people are used to using
+
+ Single object "nothrow" form, returning NULL on errors +
+ Array new
, throwing
+ bad_alloc
on errors
+
+ Array nothrow new
, returning
+ NULL
on errors
+
+ Placement new
, which does nothing (like
+ it's supposed to)
+
+ Placement array new
, which also does
+ nothing
+
+ They are distinguished by the parameters that you pass to them, like
+ any other overloaded function. The six flavors of delete
+ 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.)
+
+ Remember that it is perfectly okay to call delete
on a
+ NULL pointer! Nothing happens, by definition. That is not the
+ same thing as deleting a pointer twice.
+
+ By default, if one of the âthrowing new
sâ can't
+ allocate the memory requested, it tosses an instance of a
+ bad_alloc
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 set_new_handler()
:
+
+ 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 (&my_new_handler); + ... + } +
+ bad_alloc
is derived from the base exception
+ class defined in Chapter 19.
+