*** Welcome to piglix ***

New (C++)


In the C++ programming language, new and delete are a pair of language constructs that perform dynamic memory allocation, object construction and object destruction.

Except for a form called the "placement new", the new operator denotes a request for memory allocation on a process's heap. If sufficient memory is available, new initialises the memory, calling object constructors if necessary, and returns the address to the newly allocated and initialised memory. A new request, in its simplest form, looks as follows:

where p is a previously declared pointer of type T (or some other type to which a T pointer can be assigned, such as a superclass of T). The default constructor for T, if any, is called to construct a T instance in the allocated memory buffer.

If not enough memory is available in the free store for an object of type T, the new request indicates failure by throwing an exception of type std::bad_alloc. This removes the need to explicitly check the result of an allocation.

The deallocation counterpart of new is delete, which first calls the destructor (if any) on its argument and then returns the memory allocated by new back to the free store. Every call to new must be matched by a call to delete; failure to do so causes memory leaks.


...
Wikipedia

...