Sunday, April 09, 2006

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

Reallocate memory block.

The size of the block pointed to by memblock parameter is changed to the size in bytes specified, expanding or reducing the amount of memory accessible in that block.
The block could be moved to a new location in some cases, in this case the pointer returned by the function will point to the location. The content of the block will remain unchanged even if the block is moved and will be accessible from the new pointer.
In case that memblock is NULL the function behaves exactly as malloc assigning a new block of size bytes and returning a pointer to the beginning of it.
In case that size is 0 the memory previously allocated in memblock is deallocated and a NULL pointer is returned. Dynamic memory allocated with malloc, calloc and realloc should be freed using free once it is no longer needed.

2 comments:

Anonymous said...

dont understand...

rEd hEat said...

This is not for brainless people to understand.. :P

...anyway.. this is about c++. How we can use the realloc function to change the size of memory block accessed by a pointer. Useful in dynamic memory allocation..;) I had to use it in one of my recent assignment.. I had forgotten about this function and so this was a refreshment for me.