Difference between revisions of "cpp/memory/new"
From cppreference.com
(fix type) |
(various updates. Perhaps this could be merged into cpp/memory? It's a major topic.) |
||
Line 1: | Line 1: | ||
{{title|Low level memory management}} | {{title|Low level memory management}} | ||
{{cpp/memory/new/sidebar}} | {{cpp/memory/new/sidebar}} | ||
− | |||
− | The [[cpp/language/new | new expression]] | + | The [[cpp/language/new |new-expression]] is the only way to create an object or an array of objects with dynamic storage duration, that is, with lifetime not restricted to the scope in which it is created. A new-expression obtains storage by calling an allocation function. A [[cpp/language/delete |delete-expression]] destroys a most derived object or an array created by a new-expression and calls the deallocation function. The default allocation and deallocation functions, along with related functions, types, and objects, are declared in the header {{tt|<new>}}. |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
{{dcl list begin}} | {{dcl list begin}} | ||
− | {{dcl list h2 | Classes}} | + | {{dcl list header |new}} |
+ | {{dcl list h2 | Functions}} | ||
+ | {{dcl list fun | cpp/memory/new/operator_new | title=operator new<br>operator new[] | allocation functions }} | ||
+ | {{dcl list fun | cpp/memory/new/operator_delete | title=operator delete<br>operator delete[] | deallocation functions }} | ||
+ | {{dcl list fun | cpp/memory/new/get_new_handler | obtains the current new handler | notes={{mark c++11}}}} | ||
+ | {{dcl list fun | cpp/memory/new/set_new_handler | registers a different new handler}} | ||
+ | {{dcl list h2 | Classes }} | ||
{{dcl list class | cpp/memory/new/bad_alloc | exception thrown when memory allocation fails }} | {{dcl list class | cpp/memory/new/bad_alloc | exception thrown when memory allocation fails }} | ||
− | {{dcl list class | cpp/memory/new/bad_array_new_length | exception thrown on allocation of array with | + | {{dcl list class | cpp/memory/new/bad_array_new_length | exception thrown on allocation of array with invalid length | notes={{mark c++11}} }} |
{{dcl list class | cpp/memory/new/nothrow_t | tag type used to select an non-throwing ''allocation function'' }} | {{dcl list class | cpp/memory/new/nothrow_t | tag type used to select an non-throwing ''allocation function'' }} | ||
− | + | {{dcl list h2 | Types }} | |
− | {{dcl list h2 | Types}} | + | {{dcl list typedef | cpp/memory/new/new_handler | function pointer type of the new handler }} |
− | {{dcl list | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
{{dcl list h2 | Objects}} | {{dcl list h2 | Objects}} | ||
{{dcl list const | cpp/memory/new/nothrow | an object of type {{tt|nothrow_t}} used to select an non-throwing ''allocation function'' }} | {{dcl list const | cpp/memory/new/nothrow | an object of type {{tt|nothrow_t}} used to select an non-throwing ''allocation function'' }} | ||
{{dcl list end}} | {{dcl list end}} |
Revision as of 20:56, 27 October 2011
Template:cpp/memory/new/sidebar
The new-expression is the only way to create an object or an array of objects with dynamic storage duration, that is, with lifetime not restricted to the scope in which it is created. A new-expression obtains storage by calling an allocation function. A delete-expression destroys a most derived object or an array created by a new-expression and calls the deallocation function. The default allocation and deallocation functions, along with related functions, types, and objects, are declared in the header <new>
.
Defined in header
<new> | ||
Functions | ||
allocation functions (function) | ||
deallocation functions (function) | ||
(C++11) |
obtains the current new handler (function) | |
registers a different new handler (function) | ||
Classes | ||
exception thrown when memory allocation fails (class) | ||
(C++11) |
exception thrown on allocation of array with invalid length (class) | |
tag type used to select an non-throwing allocation function (class) | ||
Types | ||
function pointer type of the new handler (typedef) | ||
Objects | ||
an object of type nothrow_t used to select an non-throwing allocation function (constant) |