c - Behavior of realloc when the new size is the same as the old one -
i'm trying make code more efficient. have this:
typedef struct{ ... }map; map* pptr=null; map* ptemp=null; int icount=0; while (!boolean){ ptemp=(map*)realloc(pptr,(icount+1)*sizeof(map)); if (ptemp==null){ ... } pptr=ptemp; ... icount++; } the memory being allocated dynamically. reduce realloc calls make code more efficient. know how realloc behave if new size equal old one. call ignored?
it's not specified in standard c. standard c guaranteed is: contents of new object shall same of old object prior deallocation, lesser of new , old sizes.
however, if using gnu libc, says explicitely return same address, see here detail.
if new size specify same old size,
reallocguaranteed change nothing , return same address gave.
Comments
Post a Comment