4.6 KiB
[basic.stc.dynamic.general]
6 Basics [basic]
6.8 Memory and objects [basic.memobj]
6.8.6 Storage duration [basic.stc]
6.8.6.5 Dynamic storage duration [basic.stc.dynamic]
6.8.6.5.1 General [basic.stc.dynamic.general]
Objects can be created dynamically during program execution, usingnew-expressions ([expr.new]), and destroyed usingdelete-expressions ([expr.delete]).
A C++ implementation provides access to, and management of, dynamic storage via the global allocation functionsoperator new andoperator new[] and the global deallocation functionsoperator delete andoperator delete[].
[Note 1:
The non-allocating forms described in [new.delete.placement] do not perform allocation or deallocation.
â end note]
The library provides default definitions for the global allocation and deallocation functions.
Some global allocation and deallocation functions are replaceable ([dcl.fct.def.replace]).
The following allocation and deallocation functions ([support.dynamic]) are implicitly declared in global scope in each translation unit of a program.
void* operator new(std::size_t);void* operator new(std::size_t, std::align_val_t);
void operator delete(void*) noexcept;void operator delete(void*, std::size_t) noexcept;void operator delete(void*, std::align_val_t) noexcept;void operator delete(void*, std::size_t, std::align_val_t) noexcept;
void* operator new;void* operator new[](std::size_t, std::align_val_t);
void operator delete noexcept;void operator delete[](void*, std::size_t) noexcept;void operator delete[](void*, std::align_val_t) noexcept;void operator delete[](void*, std::size_t, std::align_val_t) noexcept;
These implicit declarations introduce only the function namesoperator new,operator new[],operator delete, andoperator delete[].
[Note 2:
The implicit declarations do not introduce the names std,std::size_t,std::align_val_t, or any other names that the library uses to declare these names.
Thus, a new-expression,delete-expression, or function call that refers to one of these functions without importing or including the header or importing a C++ library module ([std.modules]) is well-formed.
However, referring to std or std::size_t or std::align_val_t is ill-formed unless a standard library declaration ([cstddef.syn], [new.syn], [std.modules]) of that name precedes ([basic.lookup.general]) the use of that name.
â end note]
Allocation and/or deallocation functions may also be declared and defined for any class ([class.free]).
If the behavior of an allocation or deallocation function does not satisfy the semantic constraints specified in [basic.stc.dynamic.allocation] and [basic.stc.dynamic.deallocation], the behavior is undefined.