summaryrefslogtreecommitdiff
path: root/pjlib/include
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2005-11-21 16:58:03 +0000
committerBenny Prijono <bennylp@teluu.com>2005-11-21 16:58:03 +0000
commit4a4fe6471b8a930ec49a28cced2f7a5ea55aee26 (patch)
treec18e62b2741adebd474ee15b56d5814ea044c9a0 /pjlib/include
parent5d8ed312c380f76e442ca170f0f791273c914bfa (diff)
Small optimization in pool (removed used_size)
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@69 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib/include')
-rw-r--r--pjlib/include/pj/pool.h3
-rw-r--r--pjlib/include/pj/pool_i.h18
2 files changed, 10 insertions, 11 deletions
diff --git a/pjlib/include/pj/pool.h b/pjlib/include/pj/pool.h
index c47195c8..93d67a90 100644
--- a/pjlib/include/pj/pool.h
+++ b/pjlib/include/pj/pool.h
@@ -151,9 +151,6 @@ struct pj_pool_t
/** Current capacity allocated by the pool. */
pj_size_t capacity;
- /** Number of memory used/allocated. */
- pj_size_t used_size;
-
/** Size of memory block to be allocated when the pool runs out of memory */
pj_size_t increment_size;
diff --git a/pjlib/include/pj/pool_i.h b/pjlib/include/pj/pool_i.h
index 39c04877..05db29b7 100644
--- a/pjlib/include/pj/pool_i.h
+++ b/pjlib/include/pj/pool_i.h
@@ -29,24 +29,27 @@ PJ_IDEF(pj_size_t) pj_pool_get_capacity( pj_pool_t *pool )
PJ_IDEF(pj_size_t) pj_pool_get_used_size( pj_pool_t *pool )
{
- return pool->used_size;
+ pj_pool_block *b = pool->block_list.next;
+ pj_size_t used_size = sizeof(pj_pool_t);
+ while (b != &pool->block_list) {
+ used_size += (b->cur - b->buf) + sizeof(pj_pool_block);
+ b = b->next;
+ }
+ return used_size;
}
-PJ_IDEF(void*) pj_pool_alloc_from_block( pj_pool_t *pool,
- pj_pool_block *block, pj_size_t size )
+PJ_IDEF(void*) pj_pool_alloc_from_block( pj_pool_block *block, pj_size_t size )
{
/* The operation below is valid for size==0.
* When size==0, the function will return the pointer to the pool
* memory address, but no memory will be allocated.
*/
if (size & (PJ_POOL_ALIGNMENT-1)) {
- size &= ~(PJ_POOL_ALIGNMENT-1);
- size += PJ_POOL_ALIGNMENT;
+ size = (size + PJ_POOL_ALIGNMENT) & ~(PJ_POOL_ALIGNMENT-1);
}
if ((unsigned)(block->end - block->cur) >= size) {
void *ptr = block->cur;
block->cur += size;
- pool->used_size += size;
return ptr;
}
return NULL;
@@ -54,8 +57,7 @@ PJ_IDEF(void*) pj_pool_alloc_from_block( pj_pool_t *pool,
PJ_IDEF(void*) pj_pool_alloc( pj_pool_t *pool, pj_size_t size)
{
- pj_pool_block *block = pool->block_list.next;
- void *ptr = pj_pool_alloc_from_block(pool, block, size);
+ void *ptr = pj_pool_alloc_from_block(pool->block_list.next, size);
if (!ptr)
ptr = pj_pool_allocate_find(pool, size);
return ptr;