1
/* $Id: pool_i.h 4298 2012-11-22 05:00:01Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
#include <pj/string.h>
25
PJ_IDEF(pj_size_t) pj_pool_get_capacity( pj_pool_t *pool )
27
return pool->capacity;
30
PJ_IDEF(pj_size_t) pj_pool_get_used_size( pj_pool_t *pool )
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);
41
PJ_IDEF(void*) pj_pool_alloc_from_block( pj_pool_block *block, pj_size_t size )
43
/* The operation below is valid for size==0.
44
* When size==0, the function will return the pointer to the pool
45
* memory address, but no memory will be allocated.
47
if (size & (PJ_POOL_ALIGNMENT-1)) {
48
size = (size + PJ_POOL_ALIGNMENT) & ~(PJ_POOL_ALIGNMENT-1);
50
if ((pj_size_t)(block->end - block->cur) >= size) {
51
void *ptr = block->cur;
58
PJ_IDEF(void*) pj_pool_alloc( pj_pool_t *pool, pj_size_t size)
60
void *ptr = pj_pool_alloc_from_block(pool->block_list.next, size);
62
ptr = pj_pool_allocate_find(pool, size);
67
PJ_IDEF(void*) pj_pool_calloc( pj_pool_t *pool, pj_size_t count, pj_size_t size)
69
void *buf = pj_pool_alloc( pool, size*count);
71
pj_bzero(buf, size * count);
75
PJ_IDEF(const char *) pj_pool_getobjname( const pj_pool_t *pool )
77
return pool->obj_name;
80
PJ_IDEF(pj_pool_t*) pj_pool_create( pj_pool_factory *f,
82
pj_size_t initial_size,
83
pj_size_t increment_size,
84
pj_pool_callback *callback)
86
return (*f->create_pool)(f, name, initial_size, increment_size, callback);
89
PJ_IDEF(void) pj_pool_release( pj_pool_t *pool )
91
if (pool->factory->release_pool)
92
(*pool->factory->release_pool)(pool->factory, pool);