REALLOC - change size of allocated space.

(ANSI Standard)

Usage:

#include <stdlib.h>
newp = realloc( oldp, size );

Where:

void *oldp;
points to region of memory previously allocated by "malloc" or "calloc".
size_t size;
is the new size desired for the allocated memory.
void *newp;
points to the reallocated memory. This may be the same as "oldp" if the old block of memory could be grown (or shrunk) to the new size; otherwise, it will be a different block. The space begins at an alignment boundary that is suitable for storing objects of any data type. If memory cannot be acquired or if an argument is improperly specified, the NULL pointer is returned.

Description:

"realloc" changes the size of a block of memory previously allocated via "malloc" or "calloc". Logically "realloc" behaves like:

newp = malloc(size);
if (NULL != newp) {
    memcpy(newp, oldp, min(size, oldsize));
    free(oldp);
}
return(newp);

However, if the space is available, the operation may instead be done in place bypassing the alloc/copy/free actions.

Notes:

The following calls have the same effect:

realloc(NULL,size)
malloc(size)

See Also:

expl c lib malloc

expl c lib calloc

expl c lib free

Copyright © 1996, Thinkage Ltd.