Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

resizing buffer using realloc

Tags:

c

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.

like image 935
mawia Avatar asked Nov 28 '22 13:11

mawia


1 Answers

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

like image 111
Naveen Avatar answered Dec 16 '22 10:12

Naveen