operator delete, operator delete[]
Defined in header <new>
|
||
void operator delete ( void* ptr ); |
(1) | |
void operator delete[]( void* ptr ); |
(2) | |
void operator delete ( void* ptr, const std::nothrow_t& ); |
(3) | |
void operator delete[]( void* ptr, const std::nothrow_t& ); |
(4) | |
void operator delete ( void* ptr, void*); |
(5) | |
void operator delete[]( void* ptr, void* ); |
(6) | |
Deallocates storage. These allocation functions are called by delete-expressions to deallocate memory after destructing dynamic objects.
1) Deallocates storage, obtained by a call to operator new(size_t) or operator new(size_t, std::nothrow_t)
2) Deallocates storage, obtained by a call to operator new[](size_t) or operator new[](size_t, std::nothrow_t)
3-4) Same as 1-2) unless replaced. These versions are called by non-throwing new-expressions if a constructor they call throws an exception.
5-6) Do nothing. These versions are called by placement new expressions if a constructor they call throws an exception.
In all cases, if ptr is a null pointer, the deallocation function does nothing.
Contents |
[edit] Replacing and overloading
The versions 1-4) are implicitly declared in each translation unit even if the <new> header is not included. These functions are replaceable: a user-provided non-member function with the same signature replaces the implicit version. At most one replacement may be provided for each of the four implicit deallocation functions. Also, program can define class member versions of these functions or define allocation functions with different signatures (except 5-6) are not replaceable).
The deallocation function can be replaced/overloaded in two ways:
- in the global scope: in order to call it, the signature of the overloaded allocation functions must be visible at the place of deallocation, except for implicitly declared default deallocation functions. This allocation function will be used for all deallocations with corresponding parameters in the current program
- in the local scope: the overloaded operator delete must be static public member function of the class. This deallocation function will be used only for deallocations of that particular class.
During compilation, each delete expression looks up for appropriate deallocation function's name firstly in the class scope and after that in the global scope. It can be instructed to skip the first step. Note, that as per overloading rules, any deallocation functions declared in class scope hides all global deallocation functions. For more information see delete expression.
[edit] Parameters
ptr | - | pointer to a memory area to deallocate or a null pointer |
[edit] Return value
(none)
[edit] Exceptions
[edit] See also
[edit] See also
allocation functions (function) | |
releases uninitialized storage (function) | |
deallocates memory (function) |