diff options
-rw-r--r-- | pjlib/src/pj/pool.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/pjlib/src/pj/pool.c b/pjlib/src/pj/pool.c index dcded853..5b022a8c 100644 --- a/pjlib/src/pj/pool.c +++ b/pjlib/src/pj/pool.c @@ -66,10 +66,15 @@ static pj_pool_block *pj_pool_create_block( pj_pool_t *pool, pj_size_t size) /* Add capacity. */ pool->capacity += size; - /* Set block attribytes. */ - block->cur = block->buf = ((unsigned char*)block) + sizeof(pj_pool_block); + /* Set start and end of buffer. */ + block->buf = ((unsigned char*)block) + sizeof(pj_pool_block); block->end = ((unsigned char*)block) + size; + /* Set the start pointer, aligning it as needed */ + block->cur = (unsigned char*) + (((unsigned long)block->buf + PJ_POOL_ALIGNMENT - 1) & + ~(PJ_POOL_ALIGNMENT - 1)); + /* Insert in the front of the list. */ pj_list_insert_after(&pool->block_list, block); @@ -111,11 +116,15 @@ PJ_DEF(void*) pj_pool_allocate_find(pj_pool_t *pool, unsigned size) /* If pool is configured to expand, but the increment size * is less than the required size, expand the pool by multiple - * increment size + * increment size. Also count the size wasted due to aligning + * the block. */ - if (pool->increment_size < size + sizeof(pj_pool_block)) { + if (pool->increment_size < + size + sizeof(pj_pool_block) + PJ_POOL_ALIGNMENT) + { unsigned count; - count = (size + pool->increment_size + sizeof(pj_pool_block)) / + count = (size + pool->increment_size + sizeof(pj_pool_block) + + PJ_POOL_ALIGNMENT) / pool->increment_size; block_size = count * pool->increment_size; |