Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/memory/new"

From cppreference.com
< cpp‎ | memory
 
m (1 revision: import content)

Revision as of 14:54, 6 June 2011

Contents

Allocation

The new expression is a language builtin which is the only way to initialize objects initialize objects in dynamically obtained memory. The memory is acquired by an operator new, new[] (allocation functions).

Deallocation

The delete expression is used to destruct objects previously initialized by the new expression and deallocate memory after that. For deallocation the delete expression uses operator delete, delete[] (deallocation functions).

Note, that it is possible to explicitly call the destructor of an object and deallocation function separately, if required.

Miscellaneous

The <new> header contains declarations of default allocation and deallocation functions (note that these functions are implicitly defined in each translation unit). Also several utility functions, types and objects are declared

Template:dcl list subheadTemplate:dcl list subheadTemplate:dcl list subheadTemplate:dcl list subhead

bad_alloc

exception thrown when memory allocation fails

bad_array_new_length

exception thrown on allocation of array with greater than
implementation supported, or negative length Template:mark c++0x

nothrow_t

tag type used to select an non-throwing allocation function

new_handler

function pointer type, used in set_new_handler Template:mark c++0x

set_new_handler

sets a function which is called when an allocation function
fails to obtain more memory to the free memory pool Template:mark c++0x

nothrow

an object of type nothrow_t used to select an non-throwing allocation function