/* Resize the given region to the new size, returning a pointer to the (possibly moved) region. This is optimized for
* speed; some benchmarks seem to indicate that greater compactness is achieved by unconditionally allocating and
* copying to a new region. This module has incestuous knowledge of the internals of both mfree and mmalloc. */
/* Resize the given region to the new size, returning a pointer to the (possibly moved) region. This is optimized for
* speed; some benchmarks seem to indicate that greater compactness is achieved by unconditionally allocating and
* copying to a new region. This module has incestuous knowledge of the internals of both mfree and mmalloc. */
if ((char *) ptr < (char *) mdp->heapbase || BLOCK(ptr) > mdp->heapsize) {
printf("FIXME. Ouch, this pointer is not mine, refusing to proceed (another solution would be to malloc "
"it instead of reallocing it, see source code)\n");
if ((char *) ptr < (char *) mdp->heapbase || BLOCK(ptr) > mdp->heapsize) {
printf("FIXME. Ouch, this pointer is not mine, refusing to proceed (another solution would be to malloc "
"it instead of reallocing it, see source code)\n");
* ie return a valid block that can be realloced and freed.
* glibc malloc does not use this trick but return a constant pointer, but we need to enlist the free fragments later on.
*/
* ie return a valid block that can be realloced and freed.
* glibc malloc does not use this trick but return a constant pointer, but we need to enlist the free fragments later on.
*/
if (blocks < mdp->heapinfo[block].busy_block.size) {
int it;
/* The new size is smaller; return excess memory to the free list. */
if (blocks < mdp->heapinfo[block].busy_block.size) {
int it;
/* The new size is smaller; return excess memory to the free list. */
for (it= block+blocks; it< mdp->heapinfo[block].busy_block.size ; it++){
mdp->heapinfo[it].type = MMALLOC_TYPE_UNFRAGMENTED; // FIXME that should be useless, type should already be 0 here
mdp->heapinfo[it].busy_block.ignore = 0;
for (it= block+blocks; it< mdp->heapinfo[block].busy_block.size ; it++){
mdp->heapinfo[it].type = MMALLOC_TYPE_UNFRAGMENTED; // FIXME that should be useless, type should already be 0 here
mdp->heapinfo[it].busy_block.ignore = 0;
mdp->heaplimit = oldlimit;
result = mmalloc_no_memset(mdp, requested_size);
mdp->heaplimit = oldlimit;
result = mmalloc_no_memset(mdp, requested_size);
if (size > (size_t) (1 << (type - 1)) && size <= (size_t) (1 << type)) {
/* The new size is the same kind of fragment. */
if (size > (size_t) (1 << (type - 1)) && size <= (size_t) (1 << type)) {
/* The new size is the same kind of fragment. */
} else { /* fragment -> Either other fragment, or block */
/* The new size is different; allocate a new space,
and copy the lesser of the new size and the old. */
} else { /* fragment -> Either other fragment, or block */
/* The new size is different; allocate a new space,
and copy the lesser of the new size and the old. */