tmp/tmp42bvnw2q/{from.md → to.md}
RENAMED
|
@@ -1,63 +1,71 @@
|
|
| 1 |
-
#### Allocation functions <a id="basic.stc.dynamic.allocation">[[basic.stc.dynamic.allocation]]</a>
|
| 2 |
|
| 3 |
An allocation function shall be a class member function or a global
|
| 4 |
function; a program is ill-formed if an allocation function is declared
|
| 5 |
in a namespace scope other than global scope or declared static in
|
| 6 |
global scope. The return type shall be `void*`. The first parameter
|
| 7 |
-
shall have type `std::size_t`
|
| 8 |
-
shall not have an associated default argument
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
template
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
|
| 16 |
-
|
| 17 |
-
storage. If it is successful, it
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
allocated
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
allocation
|
| 33 |
-
[[new.delete.
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
An allocation function that fails to allocate storage can invoke the
|
| 39 |
-
currently installed new-handler function
|
| 40 |
|
| 41 |
-
[*Note
|
| 42 |
address of the currently installed `new_handler` using the
|
| 43 |
-
`std::get_new_handler` function
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
|
| 52 |
A global allocation function is only called as the result of a new
|
| 53 |
-
expression
|
| 54 |
-
syntax
|
| 55 |
-
|
|
|
|
| 56 |
|
| 57 |
-
[*Note
|
| 58 |
-
allocate storage for objects with static storage duration
|
| 59 |
-
[[basic.stc.static]]
|
| 60 |
-
duration
|
| 61 |
-
[[expr.typeid]]
|
| 62 |
-
[[except.throw]]
|
| 63 |
|
|
|
|
| 1 |
+
##### Allocation functions <a id="basic.stc.dynamic.allocation">[[basic.stc.dynamic.allocation]]</a>
|
| 2 |
|
| 3 |
An allocation function shall be a class member function or a global
|
| 4 |
function; a program is ill-formed if an allocation function is declared
|
| 5 |
in a namespace scope other than global scope or declared static in
|
| 6 |
global scope. The return type shall be `void*`. The first parameter
|
| 7 |
+
shall have type `std::size_t` [[support.types]]. The first parameter
|
| 8 |
+
shall not have an associated default argument [[dcl.fct.default]]. The
|
| 9 |
+
value of the first parameter is interpreted as the requested size of the
|
| 10 |
+
allocation. An allocation function can be a function template. Such a
|
| 11 |
+
template shall declare its return type and first parameter as specified
|
| 12 |
+
above (that is, template parameter types shall not be used in the return
|
| 13 |
+
type and first parameter type). Template allocation functions shall have
|
| 14 |
+
two or more parameters.
|
| 15 |
|
| 16 |
+
An allocation function attempts to allocate the requested amount of
|
| 17 |
+
storage. If it is successful, it returns the address of the start of a
|
| 18 |
+
block of storage whose length in bytes is at least as large as the
|
| 19 |
+
requested size. The order, contiguity, and initial value of storage
|
| 20 |
+
allocated by successive calls to an allocation function are unspecified.
|
| 21 |
+
Even if the size of the space requested is zero, the request can fail.
|
| 22 |
+
If the request succeeds, the value returned by a replaceable allocation
|
| 23 |
+
function is a non-null pointer value [[basic.compound]] `p0` different
|
| 24 |
+
from any previously returned value `p1`, unless that value `p1` was
|
| 25 |
+
subsequently passed to a replaceable deallocation function. Furthermore,
|
| 26 |
+
for the library allocation functions in [[new.delete.single]] and
|
| 27 |
+
[[new.delete.array]], `p0` represents the address of a block of storage
|
| 28 |
+
disjoint from the storage for any other object accessible to the caller.
|
| 29 |
+
The effect of indirecting through a pointer returned from a request for
|
| 30 |
+
zero size is undefined.[^14]
|
| 31 |
+
|
| 32 |
+
For an allocation function other than a reserved placement allocation
|
| 33 |
+
function [[new.delete.placement]], the pointer returned on a successful
|
| 34 |
+
call shall represent the address of storage that is aligned as follows:
|
| 35 |
+
|
| 36 |
+
- If the allocation function takes an argument of type
|
| 37 |
+
`std::align_val_t`, the storage will have the alignment specified by
|
| 38 |
+
the value of this argument.
|
| 39 |
+
- Otherwise, if the allocation function is named `operator new[]`, the
|
| 40 |
+
storage is aligned for any object that does not have new-extended
|
| 41 |
+
alignment [[basic.align]] and is no larger than the requested size.
|
| 42 |
+
- Otherwise, the storage is aligned for any object that does not have
|
| 43 |
+
new-extended alignment and is of the requested size.
|
| 44 |
|
| 45 |
An allocation function that fails to allocate storage can invoke the
|
| 46 |
+
currently installed new-handler function [[new.handler]], if any.
|
| 47 |
|
| 48 |
+
[*Note 3*: A program-supplied allocation function can obtain the
|
| 49 |
address of the currently installed `new_handler` using the
|
| 50 |
+
`std::get_new_handler` function [[get.new.handler]]. — *end note*]
|
| 51 |
|
| 52 |
+
An allocation function that has a non-throwing exception specification
|
| 53 |
+
[[except.spec]] indicates failure by returning a null pointer value. Any
|
| 54 |
+
other allocation function never returns a null pointer value and
|
| 55 |
+
indicates failure only by throwing an exception [[except.throw]] of a
|
| 56 |
+
type that would match a handler [[except.handle]] of type
|
| 57 |
+
`std::bad_alloc` [[bad.alloc]].
|
| 58 |
|
| 59 |
A global allocation function is only called as the result of a new
|
| 60 |
+
expression [[expr.new]], or called directly using the function call
|
| 61 |
+
syntax [[expr.call]], or called indirectly to allocate storage for a
|
| 62 |
+
coroutine state [[dcl.fct.def.coroutine]], or called indirectly through
|
| 63 |
+
calls to the functions in the C++ standard library.
|
| 64 |
|
| 65 |
+
[*Note 4*: In particular, a global allocation function is not called to
|
| 66 |
+
allocate storage for objects with static storage duration
|
| 67 |
+
[[basic.stc.static]], for objects or references with thread storage
|
| 68 |
+
duration [[basic.stc.thread]], for objects of type `std::type_info`
|
| 69 |
+
[[expr.typeid]], or for an exception object
|
| 70 |
+
[[except.throw]]. — *end note*]
|
| 71 |
|