realloc(3C)
_________________________________________________________________
realloc function
Change the size of a previously allocated area.
_________________________________________________________________
Calling Sequence
char *ptr, *realloc();
int size;
...
ptr = realloc(ptr, size);
where ptr is a pointer to the previously allocated area.
size is the number of bytes for the object.
Description
Use the realloc function to change the size of a previously
allocated area of memory. If size is greater than the current
block size, realloc allocates a new pointer and copies the
contents to a new block. The old block is then available.
Any pointer returned by realloc is a word-aligned byte pointer
that, after the appropriate conversion, can be used as a pointer
to any item.
The include file stdio.h defines this function.
Returns
The realloc function returns a pointer to the newly-sized block.
Related Functions
See also the alloc, alloca, calloc, and malloc functions.
Example
/* Program test for the realloc() function */
#include <stdio.h>
char *ptr, *alloc(), *realloc();
int size;
DG/UX 4.00 Page 1
Licensed material--property of copyright holder(s)
realloc(3C)
main(argc, argv)
int argc;
char *argv[];
{
size = atoi(argv[1]);
ptr = alloc(size);
printf("Size = %d bytes were in the block %o.\n", size, ptr);
size = atoi(argv[2]);
ptr = realloc(ptr, size);
printf("Size = %d bytes are now in the block %o.\n",
size, ptr);
}
A call to the program test with the numbers 512 and 1024
generates the output
Size = 512 bytes were in the block 34003702770.
Size = 1024 bytes are now in the block 34003674750.
DG/UX 4.00 Page 2
Licensed material--property of copyright holder(s)