Changeset 69
- Timestamp:
- Nov 21, 2005 4:58:03 PM (19 years ago)
- Location:
- pjproject/trunk/pjlib
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/include/pj/pool.h
r66 r69 151 151 /** Current capacity allocated by the pool. */ 152 152 pj_size_t capacity; 153 154 /** Number of memory used/allocated. */155 pj_size_t used_size;156 153 157 154 /** Size of memory block to be allocated when the pool runs out of memory */ -
pjproject/trunk/pjlib/include/pj/pool_i.h
r66 r69 30 30 PJ_IDEF(pj_size_t) pj_pool_get_used_size( pj_pool_t *pool ) 31 31 { 32 return pool->used_size; 32 pj_pool_block *b = pool->block_list.next; 33 pj_size_t used_size = sizeof(pj_pool_t); 34 while (b != &pool->block_list) { 35 used_size += (b->cur - b->buf) + sizeof(pj_pool_block); 36 b = b->next; 37 } 38 return used_size; 33 39 } 34 40 35 PJ_IDEF(void*) pj_pool_alloc_from_block( pj_pool_t *pool, 36 pj_pool_block *block, pj_size_t size ) 41 PJ_IDEF(void*) pj_pool_alloc_from_block( pj_pool_block *block, pj_size_t size ) 37 42 { 38 43 /* The operation below is valid for size==0. … … 41 46 */ 42 47 if (size & (PJ_POOL_ALIGNMENT-1)) { 43 size &= ~(PJ_POOL_ALIGNMENT-1); 44 size += PJ_POOL_ALIGNMENT; 48 size = (size + PJ_POOL_ALIGNMENT) & ~(PJ_POOL_ALIGNMENT-1); 45 49 } 46 50 if ((unsigned)(block->end - block->cur) >= size) { 47 51 void *ptr = block->cur; 48 52 block->cur += size; 49 pool->used_size += size;50 53 return ptr; 51 54 } … … 55 58 PJ_IDEF(void*) pj_pool_alloc( pj_pool_t *pool, pj_size_t size) 56 59 { 57 pj_pool_block *block = pool->block_list.next; 58 void *ptr = pj_pool_alloc_from_block(pool, block, size); 60 void *ptr = pj_pool_alloc_from_block(pool->block_list.next, size); 59 61 if (!ptr) 60 62 ptr = pj_pool_allocate_find(pool, size); -
pjproject/trunk/pjlib/src/pj/pool.c
r66 r69 46 46 47 47 LOG((pool->obj_name, "create_block(sz=%u), cur.cap=%u, cur.used=%u", 48 size, pool->capacity, p ool->used_size));48 size, pool->capacity, pj_pool_get_used_size(pool))); 49 49 50 50 /* Request memory from allocator. */ … … 58 58 /* Add capacity. */ 59 59 pool->capacity += size; 60 pool->used_size += sizeof(pj_pool_block);61 60 62 61 /* Set block attribytes. */ … … 87 86 88 87 while (block != &pool->block_list) { 89 p = pj_pool_alloc_from_block( pool,block, size);88 p = pj_pool_alloc_from_block(block, size); 90 89 if (p != NULL) 91 90 return p; … … 98 97 LOG((pool->obj_name, "Can't expand pool to allocate %u bytes " 99 98 "(used=%u, cap=%u)", 100 size, p ool->used_size, pool->capacity));99 size, pj_pool_get_used_size(pool), pool->capacity)); 101 100 (*pool->callback)(pool, size); 102 101 return NULL; … … 119 118 LOG((pool->obj_name, 120 119 "%u bytes requested, resizing pool by %u bytes (used=%u, cap=%u)", 121 size, block_size, p ool->used_size, pool->capacity));120 size, block_size, pj_pool_get_used_size(pool), pool->capacity)); 122 121 123 122 block = pj_pool_create_block(pool, block_size); … … 125 124 return NULL; 126 125 127 p = pj_pool_alloc_from_block( pool,block, size);126 p = pj_pool_alloc_from_block(block, size); 128 127 pj_assert(p != NULL); 129 128 #if PJ_DEBUG … … 143 142 pj_pool_callback *callback) 144 143 { 145 pj_pool_block *block;146 147 144 PJ_CHECK_STACK(); 148 145 149 146 pool->increment_size = increment_size; 150 147 pool->callback = callback; 151 pool->used_size = sizeof(*pool);152 block = pool->block_list.next;153 while (block != &pool->block_list) {154 pool->used_size += sizeof(pj_pool_block);155 block = block->next;156 }157 148 158 149 if (name) { … … 238 229 block->cur = block->buf; 239 230 pool->capacity = block->end - (unsigned char*)pool; 240 pool->used_size = 0;241 231 } 242 232 … … 247 237 { 248 238 LOG((pool->obj_name, "reset(): cap=%d, used=%d(%d%%)", 249 pool->capacity, pool->used_size, pool->used_size*100/pool->capacity)); 239 pool->capacity, pj_pool_get_used_size(pool), 240 pj_pool_get_used_size(pool)*100/pool->capacity)); 250 241 251 242 reset_pool(pool); … … 260 251 261 252 LOG((pool->obj_name, "destroy(): cap=%d, used=%d(%d%%), block0=%p-%p", 262 pool->capacity, pool->used_size, pool->used_size*100/pool->capacity, 253 pool->capacity, pj_pool_get_used_size(pool), 254 pj_pool_get_used_size(pool)*100/pool->capacity, 263 255 ((pj_pool_block*)pool->block_list.next)->buf, 264 256 ((pj_pool_block*)pool->block_list.next)->end)); -
pjproject/trunk/pjlib/src/pj/pool_caching.c
r66 r69 175 175 /* Reset pool. */ 176 176 PJ_LOG(4, (pool->obj_name, "recycle(): cap=%d, used=%d(%d%%)", 177 pool->capacity, pool->used_size, pool->used_size*100/pool->capacity)); 177 pool->capacity, pj_pool_get_used_size(pool), 178 pj_pool_get_used_size(pool)*100/pool->capacity)); 178 179 pj_pool_reset(pool); 179 180 … … 208 209 while (pool != (void*)&cp->used_list) { 209 210 PJ_LOG(3,("cachpool", " %12s: %8d of %8d (%d%%) used", pool->obj_name, 210 p ool->used_size, pool->capacity,211 p ool->used_size*100/pool->capacity));212 total_used += p ool->used_size;211 pj_pool_get_used_size(pool), pool->capacity, 212 pj_pool_get_used_size(pool)*100/pool->capacity)); 213 total_used += pj_pool_get_used_size(pool); 213 214 total_capacity += pool->capacity; 214 215 pool = pool->next;
Note: See TracChangeset
for help on using the changeset viewer.