- else if (pagenum + newsz <= pool.npages)
- {
- // Attempt to expand in place
- for (size_t i = pagenum + psz; 1;)
- {
- if (i == pagenum + newsz)
- {
- if (opts.options.mem_stomp)
- memset(p + blk_size - pm_bitmask_size,
- 0xF0, size - blk_size
- - pm_bitmask_size);
- memset(pool.pagetable + pagenum +
- psz, B_PAGEPLUS, newsz - psz);
- auto new_blk_size = (PAGESIZE * newsz);
- gc.free_mem -= new_blk_size - blk_size;
- // update the size cache, assuming that is very
- // likely the size of this block will be queried in
- // the near future
- pool.update_cache(p, new_blk_size);
- if (has_pm) {
- auto end_of_blk = cast(size_t**)(
- blk_base_addr + new_blk_size -
- pm_bitmask_size);
- *end_of_blk = pm_bitmask;
- }
- return p;
- }
- if (i == pool.npages)
- {
- break;
- }
- if (pool.pagetable[i] != B_FREE)
- break;
- i++;
- }
- }
- }
- // if new size is bigger or less than half
- if (blk_size < size || blk_size > size * 2)
- {
- size -= pm_bitmask_size;
- blk_size -= pm_bitmask_size;
- void* p2 = malloc(size, attrs, pm_bitmask);
- if (blk_size < size)
- size = blk_size;
- cstring.memcpy(p2, p, size);
- p = p2;