1
/* $Id: pool_dbg.c 4537 2013-06-19 06:47:43Z riza $ */
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) || \
36
(defined(PJ_WIN64) && PJ_WIN64 != 0)) && \
37
defined(PJ_DEBUG) && PJ_DEBUG!=0 && !PJ_NATIVE_STRING_IS_UNICODE
39
# define TRACE_(msg) OutputDebugString(msg)
42
/* Uncomment this to enable TRACE_ */
47
int PJ_NO_MEMORY_EXCEPTION;
50
PJ_DEF(int) pj_NO_MEMORY_EXCEPTION()
52
return PJ_NO_MEMORY_EXCEPTION;
56
PJ_DEF(pj_pool_t*) pj_pool_create_imp( const char *file, int line,
59
pj_size_t initial_size,
60
pj_size_t increment_size,
61
pj_pool_callback *callback)
67
PJ_UNUSED_ARG(factory);
68
PJ_UNUSED_ARG(initial_size);
69
PJ_UNUSED_ARG(increment_size);
71
pool = malloc(sizeof(struct pj_pool_t));
76
pj_ansi_strncpy(pool->obj_name, name, sizeof(pool->obj_name));
77
pool->obj_name[sizeof(pool->obj_name)-1] = '\0';
79
strcpy(pool->obj_name, "altpool");
83
pool->first_mem = NULL;
92
PJ_DEF(void) pj_pool_release_imp(pj_pool_t *pool)
99
PJ_DEF(const char*) pj_pool_getobjname_imp(pj_pool_t *pool)
106
PJ_DEF(void) pj_pool_reset_imp(pj_pool_t *pool)
108
struct pj_pool_mem *mem;
110
mem = pool->first_mem;
112
struct pj_pool_mem *next = mem->next;
117
pool->first_mem = NULL;
121
PJ_DEF(pj_size_t) pj_pool_get_capacity_imp(pj_pool_t *pool)
125
/* Unlimited capacity */
129
/* Get total used size */
130
PJ_DEF(pj_size_t) pj_pool_get_used_size_imp(pj_pool_t *pool)
132
return pool->used_size;
135
/* Allocate memory from the pool */
136
PJ_DEF(void*) pj_pool_alloc_imp( const char *file, int line,
137
pj_pool_t *pool, pj_size_t sz)
139
struct pj_pool_mem *mem;
144
mem = malloc(sz + sizeof(struct pj_pool_mem));
147
(*pool->cb)(pool, sz);
151
mem->next = pool->first_mem;
152
pool->first_mem = mem;
157
pj_ansi_sprintf(msg, "Mem %X (%d+%d bytes) allocated by %s:%d\r\n",
158
mem, sz, sizeof(struct pj_pool_mem),
164
return ((char*)mem) + sizeof(struct pj_pool_mem);
167
/* Allocate memory from the pool and zero the memory */
168
PJ_DEF(void*) pj_pool_calloc_imp( const char *file, int line,
169
pj_pool_t *pool, unsigned cnt,
174
mem = pj_pool_alloc_imp(file, line, pool, cnt*elemsz);
178
pj_bzero(mem, cnt*elemsz);
182
/* Allocate memory from the pool and zero the memory */
183
PJ_DEF(void*) pj_pool_zalloc_imp( const char *file, int line,
184
pj_pool_t *pool, pj_size_t sz)
186
return pj_pool_calloc_imp(file, line, pool, 1, sz);
191
#endif /* PJ_HAS_POOL_ALT_API */