I'm trying to make a code more efficient. I have something like 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 is being allocated dynamically. I would like to reduce the realloc calls to make the code more efficient. I would like to know how realloc would behave if the new size is equal to the old one. Will the call be simply ignored?
(iCount + 1) * sizeof(MAP)
at least looks nicer ... – Cyrillicrealloc
with the same size as an opportunity to relocate the allocated space to make future allocations easier. – Ademption