An allocation function shall be a class member function or a global
function; a program is ill-formed if an allocation function is declared
in a namespace scope other than global scope or declared static in
The return type shall be void*.
The value of the first parameter
is interpreted as the requested size of the allocation.
function can be a function template.
Such a template shall declare its
return type and first parameter as specified above (that is, template
parameter types shall not be used in the return type and first parameter
Template allocation functions shall have two or more parameters.
An allocation function attempts to allocate the requested amount of
If it is successful, it returns the address of the start
of a block of storage whose length in bytes is at least as large
as the requested size.
contiguity, and initial value of storage allocated by successive calls
to an allocation function are unspecified.
Even if the size of the space
requested is zero, the request can fail.
If the request succeeds, the
value returned by a replaceable allocation function
is a non-null pointer value ([basic.compound]
different from any previously returned value p1
unless that value p1
was subsequently passed to a
replaceable deallocation function.
Furthermore, for the library allocation functions
represents the address of a block of storage disjoint from the storage
for any other object accessible to the caller.
The effect of indirecting through a pointer
returned from a request for zero size is undefined.
An allocation function that fails to allocate storage can invoke the
currently installed new-handler function ([new.handler]
), if any.
A program-supplied allocation function can obtain the address of the
currently installed new_handler
— end note
An allocation function that has a non-throwing
exception specification ([except.spec]
indicates failure by returning
a null pointer value.
Any other allocation function
never returns a null pointer value and
indicates failure only by throwing an exception ([except.throw]
) of a type
that would match a handler ([except.handle]
) of type