1
/* $Id: pool_dbg.c 3553 2011-05-05 06:14:19Z 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
21
#include <pj/string.h>
23
#if PJ_HAS_POOL_ALT_API
35
#if defined(PJ_WIN32) && PJ_WIN32!=0 && defined(PJ_DEBUG) && PJ_DEBUG!=0 \
36
&& !PJ_NATIVE_STRING_IS_UNICODE
38
# define TRACE_(msg) OutputDebugString(msg)
41
/* Uncomment this to enable TRACE_ */
46
int PJ_NO_MEMORY_EXCEPTION;
49
PJ_DEF(int) pj_NO_MEMORY_EXCEPTION()
51
return PJ_NO_MEMORY_EXCEPTION;
55
PJ_DEF(pj_pool_t*) pj_pool_create_imp( const char *file, int line,
58
pj_size_t initial_size,
59
pj_size_t increment_size,
60
pj_pool_callback *callback)
66
PJ_UNUSED_ARG(factory);
67
PJ_UNUSED_ARG(initial_size);
68
PJ_UNUSED_ARG(increment_size);
70
pool = malloc(sizeof(struct pj_pool_t));
75
pj_ansi_strncpy(pool->obj_name, name, sizeof(pool->obj_name));
76
pool->obj_name[sizeof(pool->obj_name)-1] = '\0';
78
strcpy(pool->obj_name, "altpool");
82
pool->first_mem = NULL;
91
PJ_DEF(void) pj_pool_release_imp(pj_pool_t *pool)
98
PJ_DEF(const char*) pj_pool_getobjname_imp(pj_pool_t *pool)
105
PJ_DEF(void) pj_pool_reset_imp(pj_pool_t *pool)
107
struct pj_pool_mem *mem;
109
mem = pool->first_mem;
111
struct pj_pool_mem *next = mem->next;
116
pool->first_mem = NULL;
120
PJ_DEF(pj_size_t) pj_pool_get_capacity_imp(pj_pool_t *pool)
124
/* Unlimited capacity */
128
/* Get total used size */
129
PJ_DEF(pj_size_t) pj_pool_get_used_size_imp(pj_pool_t *pool)
131
return pool->used_size;
134
/* Allocate memory from the pool */
135
PJ_DEF(void*) pj_pool_alloc_imp( const char *file, int line,
136
pj_pool_t *pool, pj_size_t sz)
138
struct pj_pool_mem *mem;
143
mem = malloc(sz + sizeof(struct pj_pool_mem));
146
(*pool->cb)(pool, sz);
150
mem->next = pool->first_mem;
151
pool->first_mem = mem;
156
pj_ansi_sprintf(msg, "Mem %X (%d+%d bytes) allocated by %s:%d\r\n",
157
mem, sz, sizeof(struct pj_pool_mem),
163
return ((char*)mem) + sizeof(struct pj_pool_mem);
166
/* Allocate memory from the pool and zero the memory */
167
PJ_DEF(void*) pj_pool_calloc_imp( const char *file, int line,
168
pj_pool_t *pool, unsigned cnt,
173
mem = pj_pool_alloc_imp(file, line, pool, cnt*elemsz);
177
pj_bzero(mem, cnt*elemsz);
181
/* Allocate memory from the pool and zero the memory */
182
PJ_DEF(void*) pj_pool_zalloc_imp( const char *file, int line,
183
pj_pool_t *pool, pj_size_t sz)
185
return pj_pool_calloc_imp(file, line, pool, 1, sz);
190
#endif /* PJ_HAS_POOL_ALT_API */