673 lines
27 KiB
Markdown
673 lines
27 KiB
Markdown
[new.delete]
|
||
|
||
# 17 Language support library [[support]](./#support)
|
||
|
||
## 17.6 Dynamic memory management [[support.dynamic]](support.dynamic#new.delete)
|
||
|
||
### 17.6.3 Storage allocation and deallocation [new.delete]
|
||
|
||
#### [17.6.3.1](#general) General [[new.delete.general]](new.delete.general)
|
||
|
||
[1](#general-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2403)
|
||
|
||
Except where otherwise specified, the provisions of [[basic.stc.dynamic]](basic.stc.dynamic "6.8.6.5 Dynamic storage duration") apply to the library versions of operator new and operatordelete[.](#general-1.sentence-1)
|
||
|
||
If the value of an alignment argument
|
||
passed to any of these functions
|
||
is not a valid alignment value,
|
||
the behavior is undefined[.](#general-1.sentence-2)
|
||
|
||
[2](#general-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2412)
|
||
|
||
On freestanding implementations,
|
||
it is implementation-defined
|
||
whether the default versions of the replaceable global allocation functions
|
||
satisfy the required behaviors
|
||
described in [[new.delete.single]](#single "17.6.3.2 Single-object forms") and [[new.delete.array]](#array "17.6.3.3 Array forms")[.](#general-2.sentence-1)
|
||
|
||
[*Note [1](#general-note-1)*:
|
||
|
||
A freestanding implementation's default versions of
|
||
the replaceable global allocation functions
|
||
can cause undefined behavior when invoked[.](#general-2.sentence-2)
|
||
|
||
During constant evaluation,
|
||
the behaviors of those default versions are irrelevant,
|
||
as those calls are omitted ([[expr.new]](expr.new "7.6.2.8 New"))[.](#general-2.sentence-3)
|
||
|
||
â *end note*]
|
||
|
||
*Recommended practice*: If any of the default versions of the replaceable global allocation functions
|
||
meet the requirements of a hosted implementation, they all should[.](#general-2.sentence-4)
|
||
|
||
#### [17.6.3.2](#single) Single-object forms [[new.delete.single]](new.delete.single)
|
||
|
||
[ð](#lib:new,operator)
|
||
|
||
`void* operator new(std::size_t size);
|
||
void* operator new(std::size_t size, std::align_val_t alignment);
|
||
`
|
||
|
||
[1](#single-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2440)
|
||
|
||
*Effects*: The[allocation functions](basic.stc.dynamic.allocation "6.8.6.5.2 Allocation functions [basic.stc.dynamic.allocation]") called by a[*new-expression*](expr.new#nt:new-expression "7.6.2.8 New [expr.new]") ([[expr.new]](expr.new "7.6.2.8 New"))
|
||
to allocatesize bytes of storage[.](#single-1.sentence-1)
|
||
|
||
The second form is called for a type with new-extended alignment, and
|
||
the first form is called otherwise[.](#single-1.sentence-2)
|
||
|
||
[2](#single-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2451)
|
||
|
||
*Required behavior*: Return a non-null pointer to suitably aligned storage ([[basic.stc.dynamic]](basic.stc.dynamic "6.8.6.5 Dynamic storage duration")),
|
||
or else throw abad_allocexception[.](#single-2.sentence-1)
|
||
|
||
This requirement is binding on any replacement versions of these functions[.](#single-2.sentence-2)
|
||
|
||
[3](#single-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2460)
|
||
|
||
*Default behavior*:
|
||
|
||
- [(3.1)](#single-3.1)
|
||
|
||
Executes a loop:
|
||
Within the loop, the function first attempts to allocate the requested storage[.](#single-3.1.sentence-1)
|
||
Whether the attempt involves a call to the C standard library functionsmalloc or aligned_alloc is unspecified[.](#single-3.1.sentence-2)
|
||
|
||
- [(3.2)](#single-3.2)
|
||
|
||
Returns a pointer to the allocated storage if the attempt is successful[.](#single-3.2.sentence-1)
|
||
Otherwise, if the
|
||
current new_handler ([[get.new.handler]](get.new.handler "17.6.4.5 get_new_handler")) is
|
||
a null pointer value, throwsbad_alloc[.](#single-3.2.sentence-2)
|
||
|
||
- [(3.3)](#single-3.3)
|
||
|
||
Otherwise, the function calls the current[new_handler](new.handler "17.6.4.3 Type new_handler [new.handler]") function[.](#single-3.3.sentence-1)
|
||
If the called function returns, the loop repeats[.](#single-3.3.sentence-2)
|
||
|
||
- [(3.4)](#single-3.4)
|
||
|
||
The loop terminates when an attempt to allocate the requested storage is
|
||
successful or when a callednew_handler function does not return[.](#single-3.4.sentence-1)
|
||
|
||
[4](#single-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2487)
|
||
|
||
*Remarks*: This function is replaceable ([[dcl.fct.def.replace]](dcl.fct.def.replace#term.replaceable.function "9.6.5 Replaceable function definitions"))[.](#single-4.sentence-1)
|
||
|
||
[ð](#lib:new,operator_)
|
||
|
||
`void* operator new(std::size_t size, const std::nothrow_t&) noexcept;
|
||
void* operator new(std::size_t size, std::align_val_t alignment, const std::nothrow_t&) noexcept;
|
||
`
|
||
|
||
[5](#single-5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2499)
|
||
|
||
*Effects*: Same as above, except that these are called by a placement version of a[*new-expression*](expr.new#nt:new-expression "7.6.2.8 New [expr.new]") when a C++ program prefers a null pointer result as an error indication,
|
||
instead of abad_alloc exception[.](#single-5.sentence-1)
|
||
|
||
[6](#single-6)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2508)
|
||
|
||
*Required behavior*: Return a non-null pointer to suitably aligned storage ([[basic.stc.dynamic]](basic.stc.dynamic "6.8.6.5 Dynamic storage duration")),
|
||
or else return a null pointer[.](#single-6.sentence-1)
|
||
|
||
Each of these nothrow versions ofoperator new returns a pointer obtained as if
|
||
acquired from the (possibly replaced)
|
||
corresponding non-placement function[.](#single-6.sentence-2)
|
||
|
||
This requirement is binding on any replacement versions of these functions[.](#single-6.sentence-3)
|
||
|
||
[7](#single-7)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2519)
|
||
|
||
*Default behavior*: Calls operator new(size),
|
||
or operator new(size, alignment),
|
||
respectively[.](#single-7.sentence-1)
|
||
|
||
If the call returns normally,
|
||
returns the result of that call[.](#single-7.sentence-2)
|
||
|
||
Otherwise, returns a null pointer[.](#single-7.sentence-3)
|
||
|
||
[8](#single-8)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2528)
|
||
|
||
[*Example [1](#single-example-1)*: T* p1 = new T; // throws bad_alloc if it fails T* p2 = new(nothrow) T; // returns nullptr if it fails â *end example*]
|
||
|
||
[9](#single-9)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2536)
|
||
|
||
*Remarks*: This function is replaceable ([[dcl.fct.def.replace]](dcl.fct.def.replace#term.replaceable.function "9.6.5 Replaceable function definitions"))[.](#single-9.sentence-1)
|
||
|
||
[ð](#lib:delete,operator)
|
||
|
||
`void operator delete(void* ptr) noexcept;
|
||
void operator delete(void* ptr, std::size_t size) noexcept;
|
||
void operator delete(void* ptr, std::align_val_t alignment) noexcept;
|
||
void operator delete(void* ptr, std::size_t size, std::align_val_t alignment) noexcept;
|
||
`
|
||
|
||
[10](#single-10)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2550)
|
||
|
||
*Preconditions*: ptr is a null pointer or
|
||
its value represents the address of
|
||
a block of memory allocated by
|
||
an earlier call to a (possibly replaced)operator new(std::size_t) oroperator new(std::size_t, std::align_val_t) which has not been invalidated by an intervening call tooperator delete[.](#single-10.sentence-1)
|
||
|
||
[11](#single-11)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2562)
|
||
|
||
If the alignment parameter is not present,ptr was returned by an allocation function
|
||
without an alignment parameter[.](#single-11.sentence-1)
|
||
|
||
If present, the alignment argument
|
||
is equal to the alignment argument
|
||
passed to the allocation function that returned ptr[.](#single-11.sentence-2)
|
||
|
||
If present, the size argument
|
||
is equal to the size argument
|
||
passed to the allocation function that returned ptr[.](#single-11.sentence-3)
|
||
|
||
[12](#single-12)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2573)
|
||
|
||
*Effects*: The
|
||
deallocation functions ([[basic.stc.dynamic.deallocation]](basic.stc.dynamic.deallocation "6.8.6.5.3 Deallocation functions"))
|
||
called by a[*delete-expression*](expr.delete#nt:delete-expression "7.6.2.9 Delete [expr.delete]") ([[expr.delete]](expr.delete "7.6.2.9 Delete"))
|
||
to render the value of ptr invalid[.](#single-12.sentence-1)
|
||
|
||
[13](#single-13)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2581)
|
||
|
||
*Required behavior*: A call to an operator delete with a size parameter
|
||
may be changed to
|
||
a call to the corresponding operator delete without a size parameter,
|
||
without affecting memory allocation[.](#single-13.sentence-1)
|
||
|
||
[*Note [1](#single-note-1)*:
|
||
|
||
A conforming implementation is foroperator delete(void* ptr, std::size_t size) to simply calloperator delete(ptr)[.](#single-13.sentence-2)
|
||
|
||
â *end note*]
|
||
|
||
[14](#single-14)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2595)
|
||
|
||
*Default behavior*: The functions that have a size parameter
|
||
forward their other parameters
|
||
to the corresponding function without a size parameter[.](#single-14.sentence-1)
|
||
|
||
[*Note [2](#single-note-2)*:
|
||
|
||
See the note in the below *Remarks*: paragraph[.](#single-14.sentence-2)
|
||
|
||
â *end note*]
|
||
|
||
[15](#single-15)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2604)
|
||
|
||
*Default behavior*: If ptr is null, does nothing[.](#single-15.sentence-1)
|
||
|
||
Otherwise, reclaims the
|
||
storage allocated by the earlier call to operator new[.](#single-15.sentence-2)
|
||
|
||
[16](#single-16)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2609)
|
||
|
||
*Remarks*: It is unspecified under what conditions part or all of suchreclaimed storage will be allocated by subsequent
|
||
calls tooperator new or any ofaligned_alloc,calloc,malloc,
|
||
orrealloc,
|
||
declared in [<cstdlib>](cstdlib.syn#header:%3ccstdlib%3e "17.2.2 Header <cstdlib> synopsis [cstdlib.syn]")[.](#single-16.sentence-1)
|
||
|
||
This function is replaceable ([[dcl.fct.def.replace]](dcl.fct.def.replace#term.replaceable.function "9.6.5 Replaceable function definitions"))[.](#single-16.sentence-2)
|
||
|
||
If a replacement function
|
||
without a size parameter
|
||
is defined by the program,
|
||
the program should also define the corresponding
|
||
function with a size parameter[.](#single-16.sentence-3)
|
||
|
||
If a replacement function
|
||
with a size parameter
|
||
is defined by the program,
|
||
the program shall also define the corresponding
|
||
version without the size parameter[.](#single-16.sentence-4)
|
||
|
||
[*Note [3](#single-note-3)*:
|
||
|
||
The default behavior above might change in the future,
|
||
which will require replacing both deallocation functions
|
||
when replacing the allocation function[.](#single-16.sentence-5)
|
||
|
||
â *end note*]
|
||
|
||
[ð](#lib:delete,operator_)
|
||
|
||
`void operator delete(void* ptr, const std::nothrow_t&) noexcept;
|
||
void operator delete(void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept;
|
||
`
|
||
|
||
[17](#single-17)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2648)
|
||
|
||
*Preconditions*: ptr is a null pointer or
|
||
its value represents the address of
|
||
a block of memory allocated by
|
||
an earlier call to a (possibly replaced)operator new(std::size_t) oroperator new(std::size_t, std::align_val_t) which has not been invalidated by an intervening call tooperator delete[.](#single-17.sentence-1)
|
||
|
||
[18](#single-18)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2660)
|
||
|
||
If the alignment parameter is not present,ptr was returned by an allocation function
|
||
without an alignment parameter[.](#single-18.sentence-1)
|
||
|
||
If present, the alignment argument
|
||
is equal to the alignment argument
|
||
passed to the allocation function that returned ptr[.](#single-18.sentence-2)
|
||
|
||
[19](#single-19)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2668)
|
||
|
||
*Effects*: The
|
||
deallocation functions ([[basic.stc.dynamic.deallocation]](basic.stc.dynamic.deallocation "6.8.6.5.3 Deallocation functions"))
|
||
called by the implementation
|
||
to render the value of ptr invalid
|
||
when the constructor invoked from a nothrow
|
||
placement version of the [*new-expression*](expr.new#nt:new-expression "7.6.2.8 New [expr.new]") throws an exception[.](#single-19.sentence-1)
|
||
|
||
[20](#single-20)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2677)
|
||
|
||
*Default behavior*: Calls operator delete(ptr),
|
||
or operator delete(ptr, alignment),
|
||
respectively[.](#single-20.sentence-1)
|
||
|
||
[21](#single-21)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2683)
|
||
|
||
*Remarks*: This function is replaceable ([[dcl.fct.def.replace]](dcl.fct.def.replace#term.replaceable.function "9.6.5 Replaceable function definitions"))[.](#single-21.sentence-1)
|
||
|
||
#### [17.6.3.3](#array) Array forms [[new.delete.array]](new.delete.array)
|
||
|
||
[ð](#lib:new,operator__)
|
||
|
||
`void* operator new[](std::size_t size);
|
||
void* operator new[](std::size_t size, std::align_val_t alignment);
|
||
`
|
||
|
||
[1](#array-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2697)
|
||
|
||
*Effects*: The[allocation functions](basic.stc.dynamic.allocation "6.8.6.5.2 Allocation functions [basic.stc.dynamic.allocation]") called by the array form of a[*new-expression*](expr.new#nt:new-expression "7.6.2.8 New [expr.new]") ([[expr.new]](expr.new "7.6.2.8 New"))
|
||
to allocatesize bytes of storage[.](#array-1.sentence-1)
|
||
|
||
The second form is called for a type with new-extended alignment, and
|
||
the first form is called otherwise[.](#array-1.sentence-2)[189](#footnote-189 "It is not the direct responsibility of operator new[] or operator delete[] to note the repetition count or element size of the array. Those operations are performed elsewhere in the array new and delete expressions. The array new expression, can, however, increase the size argument to operator new[] to obtain space to store supplemental information.")
|
||
|
||
[2](#array-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2725)
|
||
|
||
*Required behavior*: Same as for
|
||
the corresponding single-object forms[.](#array-2.sentence-1)
|
||
|
||
This requirement is binding on any replacement versions of these functions[.](#array-2.sentence-2)
|
||
|
||
[3](#array-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2731)
|
||
|
||
*Default behavior*: Returnsoperator new(size),
|
||
oroperator new(size, alignment),
|
||
respectively[.](#array-3.sentence-1)
|
||
|
||
[4](#array-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2739)
|
||
|
||
*Remarks*: This function is replaceable ([[dcl.fct.def.replace]](dcl.fct.def.replace#term.replaceable.function "9.6.5 Replaceable function definitions"))[.](#array-4.sentence-1)
|
||
|
||
[ð](#lib:new,operator___)
|
||
|
||
`void* operator new[](std::size_t size, const std::nothrow_t&) noexcept;
|
||
void* operator new[](std::size_t size, std::align_val_t alignment, const std::nothrow_t&) noexcept;
|
||
`
|
||
|
||
[5](#array-5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2751)
|
||
|
||
*Effects*: Same as above, except that these are called by a placement version of a[*new-expression*](expr.new#nt:new-expression "7.6.2.8 New [expr.new]") when a C++ program prefers a null pointer result as an error indication,
|
||
instead of abad_alloc exception[.](#array-5.sentence-1)
|
||
|
||
[6](#array-6)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2760)
|
||
|
||
*Required behavior*: Return a non-null pointer to suitably aligned storage ([[basic.stc.dynamic]](basic.stc.dynamic "6.8.6.5 Dynamic storage duration")),
|
||
or else return a null pointer[.](#array-6.sentence-1)
|
||
|
||
Each of these nothrow versions ofoperator new[] returns a pointer obtained as if
|
||
acquired from the (possibly replaced)
|
||
corresponding non-placement function[.](#array-6.sentence-2)
|
||
|
||
This requirement is binding on any replacement versions of these functions[.](#array-6.sentence-3)
|
||
|
||
[7](#array-7)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2771)
|
||
|
||
*Default behavior*: Calls operator new[](size),
|
||
or operator new[](size, alignment),
|
||
respectively[.](#array-7.sentence-1)
|
||
|
||
If the call returns normally,
|
||
returns the result of that call[.](#array-7.sentence-2)
|
||
|
||
Otherwise, returns a null pointer[.](#array-7.sentence-3)
|
||
|
||
[8](#array-8)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2780)
|
||
|
||
*Remarks*: This function is replaceable ([[dcl.fct.def.replace]](dcl.fct.def.replace#term.replaceable.function "9.6.5 Replaceable function definitions"))[.](#array-8.sentence-1)
|
||
|
||
[ð](#lib:delete,operator__)
|
||
|
||
`void operator delete[](void* ptr) noexcept;
|
||
void operator delete[](void* ptr, std::size_t size) noexcept;
|
||
void operator delete[](void* ptr, std::align_val_t alignment) noexcept;
|
||
void operator delete[](void* ptr, std::size_t size, std::align_val_t alignment) noexcept;
|
||
`
|
||
|
||
[9](#array-9)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2794)
|
||
|
||
*Preconditions*: ptr is a null pointer or
|
||
its value represents the address of
|
||
a block of memory allocated by
|
||
an earlier call to a (possibly replaced)operator new[](std::size_t) oroperator new[](std::size_t, std::align_val_t) which has not been invalidated by an intervening call tooperator delete[][.](#array-9.sentence-1)
|
||
|
||
[10](#array-10)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2806)
|
||
|
||
If the alignment parameter is not present,ptr was returned by an allocation function
|
||
without an alignment parameter[.](#array-10.sentence-1)
|
||
|
||
If present, the alignment argument
|
||
is equal to the alignment argument
|
||
passed to the allocation function that returned ptr[.](#array-10.sentence-2)
|
||
|
||
If present, the size argument
|
||
is equal to the size argument
|
||
passed to the allocation function that returned ptr[.](#array-10.sentence-3)
|
||
|
||
[11](#array-11)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2817)
|
||
|
||
*Effects*: The
|
||
deallocation functions ([[basic.stc.dynamic.deallocation]](basic.stc.dynamic.deallocation "6.8.6.5.3 Deallocation functions"))
|
||
called by the array form of a[*delete-expression*](expr.delete#nt:delete-expression "7.6.2.9 Delete [expr.delete]") to render the value of ptr invalid[.](#array-11.sentence-1)
|
||
|
||
[12](#array-12)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2825)
|
||
|
||
*Required behavior*: A call to an operator delete[] with a size parameter
|
||
may be changed to
|
||
a call to the corresponding operator delete[] without a size parameter,
|
||
without affecting memory allocation[.](#array-12.sentence-1)
|
||
|
||
[*Note [1](#array-note-1)*:
|
||
|
||
A conforming implementation is foroperator delete[](void* ptr, std::size_t size) to simply calloperator delete[](ptr)[.](#array-12.sentence-2)
|
||
|
||
â *end note*]
|
||
|
||
[13](#array-13)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2839)
|
||
|
||
*Default behavior*: The functions that have a size parameter
|
||
forward their other parameters
|
||
to the corresponding function without a size parameter[.](#array-13.sentence-1)
|
||
|
||
The functions that do not have a size parameter
|
||
forward their parameters
|
||
to the corresponding operator delete (single-object) function[.](#array-13.sentence-2)
|
||
|
||
[14](#array-14)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2848)
|
||
|
||
*Remarks*: This function is replaceable ([[dcl.fct.def.replace]](dcl.fct.def.replace#term.replaceable.function "9.6.5 Replaceable function definitions"))[.](#array-14.sentence-1)
|
||
|
||
If a replacement function
|
||
without a size parameter
|
||
is defined by the program,
|
||
the program should also define the corresponding
|
||
function with a size parameter[.](#array-14.sentence-2)
|
||
|
||
If a replacement function
|
||
with a size parameter
|
||
is defined by the program,
|
||
the program shall also define the corresponding
|
||
version without the size parameter[.](#array-14.sentence-3)
|
||
|
||
[*Note [2](#array-note-2)*:
|
||
|
||
The default behavior above might change in the future,
|
||
which will require replacing both deallocation functions
|
||
when replacing the allocation function[.](#array-14.sentence-4)
|
||
|
||
â *end note*]
|
||
|
||
[ð](#lib:delete,operator___)
|
||
|
||
`void operator delete[](void* ptr, const std::nothrow_t&) noexcept;
|
||
void operator delete[](void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept;
|
||
`
|
||
|
||
[15](#array-15)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2875)
|
||
|
||
*Preconditions*: ptr is a null pointer or
|
||
its value represents the address of
|
||
a block of memory allocated by
|
||
an earlier call to a (possibly replaced)operator new[](std::size_t) oroperator new[](std::size_t, std::align_val_t) which has not been invalidated by an intervening call tooperator delete[][.](#array-15.sentence-1)
|
||
|
||
[16](#array-16)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2887)
|
||
|
||
If the alignment parameter is not present,ptr was returned by an allocation function
|
||
without an alignment parameter[.](#array-16.sentence-1)
|
||
|
||
If present, the alignment argument
|
||
is equal to the alignment argument
|
||
passed to the allocation function that returned ptr[.](#array-16.sentence-2)
|
||
|
||
[17](#array-17)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2895)
|
||
|
||
*Effects*: The
|
||
deallocation functions ([[basic.stc.dynamic.deallocation]](basic.stc.dynamic.deallocation "6.8.6.5.3 Deallocation functions"))
|
||
called by the implementation
|
||
to render the value of ptr invalid
|
||
when the constructor invoked from a nothrow
|
||
placement version of the array [*new-expression*](expr.new#nt:new-expression "7.6.2.8 New [expr.new]") throws an exception[.](#array-17.sentence-1)
|
||
|
||
[18](#array-18)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2904)
|
||
|
||
*Default behavior*: Calls operator delete[](ptr),
|
||
or operator delete[](ptr, alignment),
|
||
respectively[.](#array-18.sentence-1)
|
||
|
||
[19](#array-19)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2910)
|
||
|
||
*Remarks*: This function is replaceable ([[dcl.fct.def.replace]](dcl.fct.def.replace#term.replaceable.function "9.6.5 Replaceable function definitions"))[.](#array-19.sentence-1)
|
||
|
||
[189)](#footnote-189)[189)](#footnoteref-189)
|
||
|
||
It is not the direct responsibility ofoperator new[] oroperator delete[] to note the repetition count or element size of the array[.](#footnote-189.sentence-1)
|
||
|
||
Those operations are performed elsewhere in the arraynew anddelete expressions[.](#footnote-189.sentence-2)
|
||
|
||
The arraynew expression, can, however, increase the size argument tooperator new[] to obtain space to store supplemental information[.](#footnote-189.sentence-3)
|
||
|
||
#### [17.6.3.4](#placement) Non-allocating forms [[new.delete.placement]](new.delete.placement)
|
||
|
||
[1](#placement-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2917)
|
||
|
||
These functions are reserved; a C++ program may not define functions that displace
|
||
the versions in the C++ standard library ([[constraints]](constraints "16.4.5 Constraints on programs"))[.](#placement-1.sentence-1)
|
||
|
||
The provisions of [[basic.stc.dynamic]](basic.stc.dynamic "6.8.6.5 Dynamic storage duration") do not apply to these reserved
|
||
placement forms of operator new and operator delete[.](#placement-1.sentence-2)
|
||
|
||
[ð](#lib:new,operator____)
|
||
|
||
`constexpr void* operator new(std::size_t size, void* ptr) noexcept;
|
||
`
|
||
|
||
[2](#placement-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2929)
|
||
|
||
*Returns*: ptr[.](#placement-2.sentence-1)
|
||
|
||
[3](#placement-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2933)
|
||
|
||
*Remarks*: Intentionally performs no other action[.](#placement-3.sentence-1)
|
||
|
||
[4](#placement-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2937)
|
||
|
||
[*Example [1](#placement-example-1)*:
|
||
|
||
This can be useful for constructing an object at a known address:void* place = operator new(sizeof(Something));
|
||
Something* p = new (place) Something();
|
||
|
||
â *end example*]
|
||
|
||
[ð](#lib:new,operator_____)
|
||
|
||
`constexpr void* operator new[](std::size_t size, void* ptr) noexcept;
|
||
`
|
||
|
||
[5](#placement-5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2953)
|
||
|
||
*Returns*: ptr[.](#placement-5.sentence-1)
|
||
|
||
[6](#placement-6)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2957)
|
||
|
||
*Remarks*: Intentionally performs no other action[.](#placement-6.sentence-1)
|
||
|
||
[ð](#lib:delete,operator____)
|
||
|
||
`void operator delete(void* ptr, void*) noexcept;
|
||
`
|
||
|
||
[7](#placement-7)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2968)
|
||
|
||
*Effects*: Intentionally performs no action[.](#placement-7.sentence-1)
|
||
|
||
[8](#placement-8)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2972)
|
||
|
||
*Remarks*: Default function called when any part of the initialization in a
|
||
placement [*new-expression*](expr.new#nt:new-expression "7.6.2.8 New [expr.new]") that invokes the library's
|
||
non-array placement operator new
|
||
terminates by throwing an exception ([[expr.new]](expr.new "7.6.2.8 New"))[.](#placement-8.sentence-1)
|
||
|
||
[ð](#lib:delete,operator_____)
|
||
|
||
`void operator delete[](void* ptr, void*) noexcept;
|
||
`
|
||
|
||
[9](#placement-9)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2986)
|
||
|
||
*Effects*: Intentionally performs no action[.](#placement-9.sentence-1)
|
||
|
||
[10](#placement-10)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L2990)
|
||
|
||
*Remarks*: Default function called when any part of the initialization in a
|
||
placement [*new-expression*](expr.new#nt:new-expression "7.6.2.8 New [expr.new]") that invokes the library's
|
||
array placement operator new
|
||
terminates by throwing an exception ([[expr.new]](expr.new "7.6.2.8 New"))[.](#placement-10.sentence-1)
|
||
|
||
#### [17.6.3.5](#dataraces) Data races [[new.delete.dataraces]](new.delete.dataraces)
|
||
|
||
[1](#dataraces-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3000)
|
||
|
||
For purposes of determining the existence of data races, the library versions
|
||
of operator new, user replacement versions of global operator new,
|
||
the C standard library functionsaligned_alloc, calloc, and malloc,
|
||
the library
|
||
versions of operator delete, user replacement
|
||
versions of operator delete, the C standard library functionfree, and the C standard library function realloc shall not
|
||
introduce a data race ([[res.on.data.races]](res.on.data.races "16.4.6.10 Data race avoidance"))[.](#dataraces-1.sentence-1)
|
||
|
||
Calls to these functions that allocate or deallocate a particular unit
|
||
of storage shall occur in a single total order, and each such deallocation call
|
||
shall [happen before](intro.multithread#def:happens_before "6.10.2 Multi-threaded executions and data races [intro.multithread]") the next allocation (if any) in this order[.](#dataraces-1.sentence-2)
|