Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

realloc - memory reallocator

&pagelevel(4)&pagelevel

Syntax

#include <stdlib.h>

void *realloc(void *ptr, size_t size); 

Description

realloc() changes the size of the memory area pointed to by ptr to size bytes.
realloc() is part of a C-specific memory management package that internally administers
memory areas which are requested and subsequently freed. As far as possible, all new
requests are first satisfied from the areas that are already being managed, and only then
from the operating system.

ptr is a pointer to the start of the memory area to be altered. It must be a pointer that was
returned earlier by malloc() or calloc().

size is an integer value that specifies the new size in bytes.

Return val.

Pointer to the start of the reallocated memory area



if successful.

 

Null pointer

if realloc() could not reallocate the space, e.g. because there was not
enough memory available or because an error occurred.
errno is set to indicate the error.

Errors

realloc() will fail if:

ENOMEM      There is not enough memory available.

Notes

Changing the size of a memory area with realloc() may cause the allocated block to be
shifted. In such cases, the contents of the pointer passed as an argument are not identical
to the return value.
The contents of the block are preserved up to the minimum of the old (when enlarging) and
new (when reducing) sizes.

If realloc() returns a null pointer, the block to which ptr points may have been destroyed!

If ptr is a null pointer, realloc() has the same effect as a malloc call for the specified size.

See also

calloc(), free(), malloc(), stdlib.h.