realloc
OS/161 Reference Manual
Name
realloc - resize allocated memory
Library
Standard C Library (libc, -lc)
Synopsis
#include <stdlib.h>
void *
realloc(void *ptr, size_t newsize);
Description
realloc attempts to change the size of the memory block pointed to by
ptr to newsize, causing the block to shrink or grow
as necessary. The size of NULL is treated as 0. Any newly allocated
space has undefined contents; the contents of existing space not
discarded by shrinkage are preserved.
ptr be NULL or have been previously returned by
malloc, calloc, or
realloc.
The alignment and other restrictions described for
malloc apply equally to realloc.
Return Values
realloc returns a pointer to the resized memory block. This may not be
the same pointer as ptr if for internal reasons it is
necessary to move the memory block. If such a move takes place, the
old block is invalidated and ptr becomes invalid.
If the resize operation cannot be performed, NULL is returned, in
which case the original block pointed to by ptr is untouched
and remains valid.
See Also
calloc,
malloc,
free