Defined in header
void* realloc( void* ptr, std::size_t new_size );
The reallocation is done by either:
ptr, if possible. The contents of the area remain unchanged up to the lesser of the new and old sizes. If the area is expanded, the contents of the new part of the array are undefined.
new_sizebytes, copying memory area with size equal the lesser of the new and the old sizes, and freeing the old block.
If there is not enough memory, the old memory block is not freed and null-pointer is returned.
new_size is zero, the behavior is implementation defined (null pointer may be returned, or some non-null pointer may be returned that may not be used to access storage).
Because reallocation may involve bytewise copying (regardless of whether it's to expand or to contract), only the objects of
TriviallyCopyable types are safe to access in the preserved part of the memory block after a call to
Some non-standard libraries define a type trait "BitwiseMovable" or "Relocatable", which describes a type that
- does not have to register with an observer that maintains a pointer to this object (e.g. nodes of a list or a tree)
- has no members of pointer type that point to members of the same object
Objects of such type can be accessed after their storage is reallocated even if their copy constructors are not trivial.
|ptr||-||pointer to the memory area to be reallocated|
|new_size||-||new size of the array|
 Return value
|This section is incomplete|
Reason: no example
 See also
C documentation for realloc