Guardian C Library Calls Reference Manual
realloc
3-152 128833—Guardian TNS C Library Calls Reference Manual
Reference to Library Calls
realloc
The realloc function changes the size of a block of memory that you have allocated
using malloc or calloc.
str_ptr
points to an array of characters.
size
specifies the new size in bytes of the block of memory.
Return Value
points to the reallocated block of memory if the operation is successful; otherwise,
realloc returns the pointer value NULL.
Usage Guidelines
•
In many cases, the pointer returned by realloc is the same as str_ptr. However, if you
are increasing the size of a block of memory, lack of space could cause the run-time
library to copy the block to a new area.
•
If you have compiled your program for the large-memory model, realloc will
automatically enlarge the extended data segment when necessary.
Example
This example allocates an extra 5 bytes of memory for ptr to accommodate an expanded
string:
#include <stdlibh>
#include <stringh>
ptr = (char *)malloc(6);
/* ... */
strcpy(ptr, "01234");
/* ... */
ptr = realloc(ptr, 11);
strcat(ptr, "56789");
/* ... */
#include <stdlibh>
void *realloc(void *str_ptr, size_t size);