Difference between revisions of "cpp/memory/new"
From cppreference.com
m (Shorten template names. Use {{lc}} where appropriate.) |
Andreas Krug (Talk | contribs) m (fmt) |
||
(6 intermediate revisions by 5 users not shown) | |||
Line 2: | Line 2: | ||
{{cpp/memory/new/navbar}} | {{cpp/memory/new/navbar}} | ||
− | 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 {{ | + | 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 {{header|new}}. |
{{dsc begin}} | {{dsc begin}} | ||
− | {{dsc header |new}} | + | {{dsc header|new}} |
− | {{dsc h2 | Functions}} | + | {{dsc h2|Functions}} |
− | {{dsc inc | cpp/memory/new/ | + | {{dsc inc|cpp/memory/new/dsc operator_new}} |
− | {{dsc inc | cpp/memory/new/ | + | {{dsc inc|cpp/memory/new/dsc operator_delete}} |
− | {{dsc inc | cpp/memory/new/ | + | {{dsc inc|cpp/memory/new/dsc get_new_handler}} |
− | {{dsc inc | cpp/memory/new/ | + | {{dsc inc|cpp/memory/new/dsc set_new_handler}} |
− | {{dsc h2 | Classes }} | + | {{dsc h2|Classes}} |
− | {{dsc inc | cpp/memory/new/ | + | {{dsc inc|cpp/memory/new/dsc bad_alloc}} |
− | {{dsc inc | cpp/memory/new/ | + | {{dsc inc|cpp/memory/new/dsc bad_array_new_length}} |
− | {{dsc inc | cpp/memory/new/ | + | {{dsc inc|cpp/memory/new/dsc align_val_t}} |
− | {{dsc h2 | Types }} | + | {{dsc h2|Types}} |
− | {{dsc inc | cpp/memory/new/ | + | {{dsc inc|cpp/memory/new/dsc new_handler}} |
− | {{dsc h2 | Objects}} | + | {{dsc h2|Objects}} |
− | {{dsc inc | cpp/memory/new/ | + | {{dsc inc|cpp/memory/new/dsc nothrow}} |
+ | {{dsc inc|cpp/memory/new/dsc destroying_delete}} | ||
+ | {{dsc h2|Object access}} | ||
+ | {{dsc inc|cpp/utility/dsc launder}} | ||
{{dsc end}} | {{dsc end}} | ||
− | + | {{langlinks|de|es|fr|it|ja|pt|ru|zh}} | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + |
Latest revision as of 07:56, 16 December 2023
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 new handler (function) | ||
Classes | ||
exception thrown when memory allocation fails (class) | ||
(C++11) |
exception thrown on allocation of array with invalid length (class) | |
(C++17) |
type used to pass alignment to alignment-aware allocation and deallocation functions (enum) | |
Types | ||
function pointer type of the new handler (typedef) | ||
Objects | ||
a tag used to select a non-throwing allocation function (tag) | ||
a tag used to select destroying-delete overloads of operator delete (tag) | ||
Object access | ||
(C++17) |
pointer optimization barrier (function template) |