It is important to do it like this because if realloc() were to fail and you were to assign data the return value rather than use the temporary pointer, data would be assigned NULL and the memory that data previously pointed to would now be inaccessible which makes it impossible to free() it which causes a memory leak.
3)
realloc() calls are expensive in terms of time, so don't use them with great frequency. In other words, if you have a buffer that may need to grow over time, choose a chunk size that's big enough such that the number of calls to realloc() is kept at a minimum. There's a balance here between abusing memory and abusing speed, which obviously requires different decisions depending on the problem.
I don't know of any sites offhand that address realloc() specifically, but this might help:
What for?
char **ppcArray;
if you are trying to realloc this array of string you will realloc only the array of pointers not your strings and all values of pointers will stay valid.
So what are you trying to put in tmp pointer?
In other case if you have
char (*pacArray)[100];
You will realoc all data by one call to realloc.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.