Search code examples
crealloc

resizing buffer using realloc


If the area pointed to was moved, a free(ptr) is done.

Can you please explain the above line about realloc()? This line is from a man page for calloc, malloc, realloc and free.


Solution

  • I think this explains it better:

    If sufficient space does not exist to expand the current block in its current location, a new block of the size for size is allocated, and existing data is copied from the old block to the beginning of the new block. The old block is freed, and the function returns a pointer to the new block.

    Reference taken from realloc in C