tmp/tmpr_k_7mmh/{from.md → to.md}
RENAMED
|
@@ -1,28 +1,35 @@
|
|
| 1 |
#### Single-object forms <a id="new.delete.single">[[new.delete.single]]</a>
|
| 2 |
|
| 3 |
``` cpp
|
| 4 |
void* operator new(std::size_t size);
|
|
|
|
| 5 |
```
|
| 6 |
|
| 7 |
-
*Effects:* The
|
| 8 |
called by a *new-expression* ([[expr.new]]) to allocate `size` bytes of
|
| 9 |
-
storage
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
*Replaceable:*
|
| 12 |
-
|
| 13 |
-
library.
|
| 14 |
|
| 15 |
*Required behavior:* Return a non-null pointer to suitably aligned
|
| 16 |
storage ([[basic.stc.dynamic]]), or else throw a `bad_alloc` exception.
|
| 17 |
-
This requirement is binding on
|
|
|
|
| 18 |
|
| 19 |
*Default behavior:*
|
| 20 |
|
| 21 |
- Executes a loop: Within the loop, the function first attempts to
|
| 22 |
allocate the requested storage. Whether the attempt involves a call to
|
| 23 |
-
the
|
|
|
|
| 24 |
- Returns a pointer to the allocated storage if the attempt is
|
| 25 |
successful. Otherwise, if the current
|
| 26 |
`new_handler` ([[get.new.handler]]) is a null pointer value, throws
|
| 27 |
`bad_alloc`.
|
| 28 |
- Otherwise, the function calls the current `new_handler`
|
|
@@ -31,125 +38,136 @@ This requirement is binding on a replacement version of this function.
|
|
| 31 |
- The loop terminates when an attempt to allocate the requested storage
|
| 32 |
is successful or when a called `new_handler` function does not return.
|
| 33 |
|
| 34 |
``` cpp
|
| 35 |
void* operator new(std::size_t size, const std::nothrow_t&) noexcept;
|
|
|
|
| 36 |
```
|
| 37 |
|
| 38 |
-
*Effects:* Same as above, except that
|
| 39 |
version of a *new-expression* when a C++program prefers a null pointer
|
| 40 |
result as an error indication, instead of a `bad_alloc` exception.
|
| 41 |
|
| 42 |
-
*Replaceable:*
|
| 43 |
-
|
| 44 |
-
library.
|
| 45 |
|
| 46 |
*Required behavior:* Return a non-null pointer to suitably aligned
|
| 47 |
-
storage ([[basic.stc.dynamic]]), or else return a null pointer.
|
| 48 |
-
nothrow
|
| 49 |
-
acquired from the (possibly replaced)
|
| 50 |
-
is binding on
|
|
|
|
| 51 |
|
| 52 |
-
*Default behavior:* Calls `operator new(size)`
|
|
|
|
| 53 |
normally, returns the result of that call. Otherwise, returns a null
|
| 54 |
pointer.
|
| 55 |
|
|
|
|
|
|
|
| 56 |
``` cpp
|
| 57 |
T* p1 = new T; // throws bad_alloc if it fails
|
| 58 |
T* p2 = new(nothrow) T; // returns nullptr if it fails
|
| 59 |
```
|
| 60 |
|
|
|
|
|
|
|
| 61 |
``` cpp
|
| 62 |
void operator delete(void* ptr) noexcept;
|
| 63 |
void operator delete(void* ptr, std::size_t size) noexcept;
|
|
|
|
|
|
|
| 64 |
```
|
| 65 |
|
| 66 |
-
*Effects:* The
|
| 67 |
-
|
| 68 |
*delete-expression* to render the value of `ptr` invalid.
|
| 69 |
|
| 70 |
-
*Replaceable:*
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
`size` parameter) is defined, the program should also define
|
| 74 |
-
`void operator delete(void* ptr, std::size_t size) noexcept`. If this
|
| 75 |
-
function with `size` parameter is defined, the program shall also define
|
| 76 |
-
the version without the `size` parameter. The default behavior below may
|
| 77 |
-
change in the future, which will require replacing both deallocation
|
| 78 |
-
functions when replacing the allocation function.
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
*Requires:* If an implementation has strict pointer
|
| 87 |
safety ([[basic.stc.dynamic.safety]]) then `ptr` shall be a
|
| 88 |
safely-derived pointer.
|
| 89 |
|
| 90 |
-
*Requires:* If
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
-
*Required behavior:*
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
| 97 |
`operator delete(void* ptr, std::size_t size)` to simply call
|
| 98 |
-
`operator delete(ptr)`.
|
| 99 |
|
| 100 |
-
*Default behavior:*
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
| 104 |
|
| 105 |
*Default behavior:* If `ptr` is null, does nothing. Otherwise, reclaims
|
| 106 |
the storage allocated by the earlier call to `operator new`.
|
| 107 |
|
| 108 |
*Remarks:* It is unspecified under what conditions part or all of such
|
| 109 |
reclaimed storage will be allocated by subsequent calls to
|
| 110 |
-
`operator new` or any of `
|
| 111 |
-
`<cstdlib>`.
|
| 112 |
|
| 113 |
``` cpp
|
| 114 |
void operator delete(void* ptr, const std::nothrow_t&) noexcept;
|
| 115 |
-
void operator delete(void* ptr, std::
|
| 116 |
```
|
| 117 |
|
| 118 |
-
*Effects:* The
|
| 119 |
-
|
| 120 |
implementation to render the value of `ptr` invalid when the constructor
|
| 121 |
invoked from a nothrow placement version of the *new-expression* throws
|
| 122 |
an exception.
|
| 123 |
|
| 124 |
-
*Replaceable:*
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
both deallocation functions when replacing the allocation function.
|
| 134 |
|
| 135 |
*Requires:* If an implementation has strict pointer
|
| 136 |
safety ([[basic.stc.dynamic.safety]]) then `ptr` shall be a
|
| 137 |
safely-derived pointer.
|
| 138 |
|
| 139 |
-
*Requires:* If
|
| 140 |
-
|
|
|
|
|
|
|
|
|
|
| 141 |
|
| 142 |
-
*
|
| 143 |
-
`operator delete(
|
| 144 |
-
may be changed to calls to
|
| 145 |
-
`operator delete(void* ptr, const std::nothrow_t&)` without affecting
|
| 146 |
-
memory allocation. A conforming implementation is for
|
| 147 |
-
`operator delete(void* ptr, std::size_t size, const std::nothrow_t&)` to
|
| 148 |
-
simply call `operator delete(void* ptr, const std::nothrow_t&)`.
|
| 149 |
-
|
| 150 |
-
*Default behavior:*
|
| 151 |
-
`operator delete(void* ptr, std::size_t size, const std::nothrow_t&)`
|
| 152 |
-
calls `operator delete(ptr, std::nothrow)`, and
|
| 153 |
-
`operator delete(void* ptr, const std::nothrow_t&)` calls
|
| 154 |
-
`operator delete(ptr)`.
|
| 155 |
|
|
|
|
| 1 |
#### Single-object forms <a id="new.delete.single">[[new.delete.single]]</a>
|
| 2 |
|
| 3 |
``` cpp
|
| 4 |
void* operator new(std::size_t size);
|
| 5 |
+
void* operator new(std::size_t size, std::align_val_t alignment);
|
| 6 |
```
|
| 7 |
|
| 8 |
+
*Effects:* The allocation functions ([[basic.stc.dynamic.allocation]])
|
| 9 |
called by a *new-expression* ([[expr.new]]) to allocate `size` bytes of
|
| 10 |
+
storage. The second form is called for a type with new-extended
|
| 11 |
+
alignment, and allocates storage with the specified alignment. The first
|
| 12 |
+
form is called otherwise, and allocates storage suitably aligned to
|
| 13 |
+
represent any object of that size provided the object’s type does not
|
| 14 |
+
have new-extended alignment.
|
| 15 |
|
| 16 |
+
*Replaceable:* A C++program may define functions with either of these
|
| 17 |
+
function signatures, and thereby displace the default versions defined
|
| 18 |
+
by the C++standard library.
|
| 19 |
|
| 20 |
*Required behavior:* Return a non-null pointer to suitably aligned
|
| 21 |
storage ([[basic.stc.dynamic]]), or else throw a `bad_alloc` exception.
|
| 22 |
+
This requirement is binding on any replacement versions of these
|
| 23 |
+
functions.
|
| 24 |
|
| 25 |
*Default behavior:*
|
| 26 |
|
| 27 |
- Executes a loop: Within the loop, the function first attempts to
|
| 28 |
allocate the requested storage. Whether the attempt involves a call to
|
| 29 |
+
the C standard library functions `malloc` or `aligned_alloc` is
|
| 30 |
+
unspecified.
|
| 31 |
- Returns a pointer to the allocated storage if the attempt is
|
| 32 |
successful. Otherwise, if the current
|
| 33 |
`new_handler` ([[get.new.handler]]) is a null pointer value, throws
|
| 34 |
`bad_alloc`.
|
| 35 |
- Otherwise, the function calls the current `new_handler`
|
|
|
|
| 38 |
- The loop terminates when an attempt to allocate the requested storage
|
| 39 |
is successful or when a called `new_handler` function does not return.
|
| 40 |
|
| 41 |
``` cpp
|
| 42 |
void* operator new(std::size_t size, const std::nothrow_t&) noexcept;
|
| 43 |
+
void* operator new(std::size_t size, std::align_val_t alignment, const std::nothrow_t&) noexcept;
|
| 44 |
```
|
| 45 |
|
| 46 |
+
*Effects:* Same as above, except that these are called by a placement
|
| 47 |
version of a *new-expression* when a C++program prefers a null pointer
|
| 48 |
result as an error indication, instead of a `bad_alloc` exception.
|
| 49 |
|
| 50 |
+
*Replaceable:* A C++program may define functions with either of these
|
| 51 |
+
function signatures, and thereby displace the default versions defined
|
| 52 |
+
by the C++standard library.
|
| 53 |
|
| 54 |
*Required behavior:* Return a non-null pointer to suitably aligned
|
| 55 |
+
storage ([[basic.stc.dynamic]]), or else return a null pointer. Each of
|
| 56 |
+
these nothrow versions of `operator new` returns a pointer obtained as
|
| 57 |
+
if acquired from the (possibly replaced) corresponding non-placement
|
| 58 |
+
function. This requirement is binding on any replacement versions of
|
| 59 |
+
these functions.
|
| 60 |
|
| 61 |
+
*Default behavior:* Calls `operator new(size)`, or
|
| 62 |
+
`operator new(size, alignment)`, respectively. If the call returns
|
| 63 |
normally, returns the result of that call. Otherwise, returns a null
|
| 64 |
pointer.
|
| 65 |
|
| 66 |
+
[*Example 1*:
|
| 67 |
+
|
| 68 |
``` cpp
|
| 69 |
T* p1 = new T; // throws bad_alloc if it fails
|
| 70 |
T* p2 = new(nothrow) T; // returns nullptr if it fails
|
| 71 |
```
|
| 72 |
|
| 73 |
+
— *end example*]
|
| 74 |
+
|
| 75 |
``` cpp
|
| 76 |
void operator delete(void* ptr) noexcept;
|
| 77 |
void operator delete(void* ptr, std::size_t size) noexcept;
|
| 78 |
+
void operator delete(void* ptr, std::align_val_t alignment) noexcept;
|
| 79 |
+
void operator delete(void* ptr, std::size_t size, std::align_val_t alignment) noexcept;
|
| 80 |
```
|
| 81 |
|
| 82 |
+
*Effects:* The deallocation
|
| 83 |
+
functions ([[basic.stc.dynamic.deallocation]]) called by a
|
| 84 |
*delete-expression* to render the value of `ptr` invalid.
|
| 85 |
|
| 86 |
+
*Replaceable:* A C++program may define functions with any of these
|
| 87 |
+
function signatures, and thereby displace the default versions defined
|
| 88 |
+
by the C++standard library.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
+
If a function without a `size` parameter is defined, the program should
|
| 91 |
+
also define the corresponding function with a `size` parameter. If a
|
| 92 |
+
function with a `size` parameter is defined, the program shall also
|
| 93 |
+
define the corresponding version without the `size` parameter.
|
| 94 |
+
|
| 95 |
+
[*Note 1*: The default behavior below may change in the future, which
|
| 96 |
+
will require replacing both deallocation functions when replacing the
|
| 97 |
+
allocation function. — *end note*]
|
| 98 |
+
|
| 99 |
+
*Requires:* `ptr` shall be a null pointer or its value shall represent
|
| 100 |
+
the address of a block of memory allocated by an earlier call to a
|
| 101 |
+
(possibly replaced) `operator new(std::size_t)` or
|
| 102 |
+
`operator new(std::size_t, std::align_val_t)` which has not been
|
| 103 |
+
invalidated by an intervening call to `operator delete`.
|
| 104 |
|
| 105 |
*Requires:* If an implementation has strict pointer
|
| 106 |
safety ([[basic.stc.dynamic.safety]]) then `ptr` shall be a
|
| 107 |
safely-derived pointer.
|
| 108 |
|
| 109 |
+
*Requires:* If the `alignment` parameter is not present, `ptr` shall
|
| 110 |
+
have been returned by an allocation function without an `alignment`
|
| 111 |
+
parameter. If present, the `alignment` argument shall equal the
|
| 112 |
+
`alignment` argument passed to the allocation function that returned
|
| 113 |
+
`ptr`. If present, the `size` argument shall equal the `size` argument
|
| 114 |
+
passed to the allocation function that returned `ptr`.
|
| 115 |
|
| 116 |
+
*Required behavior:* A call to an `operator delete` with a `size`
|
| 117 |
+
parameter may be changed to a call to the corresponding
|
| 118 |
+
`operator delete` without a `size` parameter, without affecting memory
|
| 119 |
+
allocation.
|
| 120 |
+
|
| 121 |
+
[*Note 2*: A conforming implementation is for
|
| 122 |
`operator delete(void* ptr, std::size_t size)` to simply call
|
| 123 |
+
`operator delete(ptr)`. — *end note*]
|
| 124 |
|
| 125 |
+
*Default behavior:* The functions that have a `size` parameter forward
|
| 126 |
+
their other parameters to the corresponding function without a `size`
|
| 127 |
+
parameter.
|
| 128 |
+
|
| 129 |
+
[*Note 3*: See the note in the above *Replaceable:*
|
| 130 |
+
paragraph. — *end note*]
|
| 131 |
|
| 132 |
*Default behavior:* If `ptr` is null, does nothing. Otherwise, reclaims
|
| 133 |
the storage allocated by the earlier call to `operator new`.
|
| 134 |
|
| 135 |
*Remarks:* It is unspecified under what conditions part or all of such
|
| 136 |
reclaimed storage will be allocated by subsequent calls to
|
| 137 |
+
`operator new` or any of `aligned_alloc`, `calloc`, `malloc`, or
|
| 138 |
+
`realloc`, declared in `<cstdlib>`.
|
| 139 |
|
| 140 |
``` cpp
|
| 141 |
void operator delete(void* ptr, const std::nothrow_t&) noexcept;
|
| 142 |
+
void operator delete(void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept;
|
| 143 |
```
|
| 144 |
|
| 145 |
+
*Effects:* The deallocation
|
| 146 |
+
functions ([[basic.stc.dynamic.deallocation]]) called by the
|
| 147 |
implementation to render the value of `ptr` invalid when the constructor
|
| 148 |
invoked from a nothrow placement version of the *new-expression* throws
|
| 149 |
an exception.
|
| 150 |
|
| 151 |
+
*Replaceable:* A C++program may define functions with either of these
|
| 152 |
+
function signatures, and thereby displace the default versions defined
|
| 153 |
+
by the C++standard library.
|
| 154 |
+
|
| 155 |
+
*Requires:* `ptr` shall be a null pointer or its value shall represent
|
| 156 |
+
the address of a block of memory allocated by an earlier call to a
|
| 157 |
+
(possibly replaced) `operator new(std::size_t)` or
|
| 158 |
+
`operator new(std::size_t, std::align_val_t)` which has not been
|
| 159 |
+
invalidated by an intervening call to `operator delete`.
|
|
|
|
| 160 |
|
| 161 |
*Requires:* If an implementation has strict pointer
|
| 162 |
safety ([[basic.stc.dynamic.safety]]) then `ptr` shall be a
|
| 163 |
safely-derived pointer.
|
| 164 |
|
| 165 |
+
*Requires:* If the `alignment` parameter is not present, `ptr` shall
|
| 166 |
+
have been returned by an allocation function without an `alignment`
|
| 167 |
+
parameter. If present, the `alignment` argument shall equal the
|
| 168 |
+
`alignment` argument passed to the allocation function that returned
|
| 169 |
+
`ptr`.
|
| 170 |
|
| 171 |
+
*Default behavior:* Calls `operator delete(ptr)`, or
|
| 172 |
+
`operator delete(ptr, alignment)`, respectively.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
|