int type;
size_t block, blocks, oldlimit;
-
if (size == 0) {
mfree(md, ptr);
return (mmalloc(md, 0));
return result;
}
- LOCK(mdp);
if (mdp->mrealloc_hook != NULL) {
- UNLOCK(mdp);
return ((*mdp->mrealloc_hook) (md, ptr, size));
}
case 0:
/* Maybe reallocate a large block to a small fragment. */
if (size <= BLOCKSIZE / 2) {
- UNLOCK(mdp);
//printf("(%s) alloc large block...",xbt_thread_self_name());
result = mmalloc(md, size);
if (result != NULL) {
/* The new size is a large allocation as well;
see if we can hold it in place. */
- LOCK(mdp);
blocks = BLOCKIFY(size);
if (blocks < mdp->heapinfo[block].busy.info.size) {
/* The new size is smaller; return excess memory to the free list. */
mdp->heaplimit = 0;
mfree(md, ptr);
mdp->heaplimit = oldlimit;
- UNLOCK(mdp);
result = mmalloc(md, size);
if (result == NULL) {
mmalloc(md, blocks * BLOCKSIZE);
}
if (ptr != result)
memmove(result, ptr, blocks * BLOCKSIZE);
- LOCK(mdp);
}
break;
and copy the lesser of the new size and the old. */
//printf("(%s) new size is different...",xbt_thread_self_name());
- UNLOCK(mdp);
result = mmalloc(md, size);
if (result == NULL)
return (NULL);