This commit is contained in:
Jeremy Hylton 2006-02-28 18:29:00 +00:00
parent 14ca327f99
commit 08533fdad6

View file

@ -54,7 +54,8 @@ PyArenaList_FreeObject(PyArenaList *alist)
static block * static block *
block_new(size_t size) block_new(size_t size)
{ {
/* Allocate header and block as one unit. ab_mem points just past header. */ /* Allocate header and block as one unit.
ab_mem points just past header. */
block *b = (block *)malloc(sizeof(block) + size); block *b = (block *)malloc(sizeof(block) + size);
if (!b) if (!b)
return NULL; return NULL;
@ -80,11 +81,13 @@ block_alloc(block *b, size_t size)
void *p; void *p;
assert(b); assert(b);
if (b->ab_offset + size > b->ab_size) { if (b->ab_offset + size > b->ab_size) {
/* If we need to allocate more memory than will fit in the default /* If we need to allocate more memory than will fit in
block, allocate a one-off block that is exactly the right size. */ the default block, allocate a one-off block that is
/* TODO(jhylton): Think more about space waste at end of block */ exactly the right size. */
/* TODO(jhylton): Think about space waste at end of block */
block *new = block_new( block *new = block_new(
size < DEFAULT_BLOCK_SIZE ? DEFAULT_BLOCK_SIZE : size); size < DEFAULT_BLOCK_SIZE ?
DEFAULT_BLOCK_SIZE : size);
if (!new) if (!new)
return NULL; return NULL;
assert(!b->ab_next); assert(!b->ab_next);