[Python-Dev] pymalloc killer
Marangozov, Vladimir (Vladimir)
Wed, 3 Apr 2002 16:50:19 +0200
[Tim, in obmalloc.c]
> #define ADDRESS_IN_RANGE(P, I) \
> ((I) < narenas && (uptr)(P) - arenas[I] < (uptr)ARENA_SIZE)
Bravo! Very nice.
Now that the pool header is reduced in size by one slot, I can only
suggest a small optimization to get rid off the multiplication when
trying to extend the free list. Since you know the code by heart
already, this should be self explanatory. It's only 3 lines of code:
1) add a member in the pool struct, after capacity:
uint lastoffset; /* free list tail block offset */
2) In malloc, in the "try to extend the free list" block:
size <<= ALIGNMENT_SHIFT; /* block size */
pool->lastoffset += size;
pool->freeblock = (block *)pool + pool->lastoffset;
3) In the "init_pool" block:
pool->capacity = ...
pool->lastoffset = POOL_OVERHEAD + size;
In other words, the lastoffset acts as an upper bound watermark.
I didn't want to do that optimization before, because it would have
resulted in a bigger pool header and waste of space. Now it's ok.