What realloc(ptr, newsize) does is that it adjusts the size of the allocated block (ptr) to newsize, copying the contents to a new location if necessary. The contents are unchanged upto the lesser of the new and old sizes.
My question is ... if the contents are copied to a new location, is it guranteed that the old location is freed, and made available for use again??
(Note: Some versions of realloc work fine if ptr points to a block freed since the last call of malloc, realloc, or calloc, so that the following is legal...
free(ptr);
realloc(ptr, newsize);
But this technique is NOT recommended because not all C implementations preserve memory after it has been freed.)
So? Bye.
Ankan.
Please do correct me if I am wrong. s-)
My question is ... if the contents are copied to a new location, is it guranteed that the old location is freed, and made available for use again??
(Note: Some versions of realloc work fine if ptr points to a block freed since the last call of malloc, realloc, or calloc, so that the following is legal...
free(ptr);
realloc(ptr, newsize);
But this technique is NOT recommended because not all C implementations preserve memory after it has been freed.)
So? Bye.
Ankan.
Please do correct me if I am wrong. s-)