27 xht pool__disturbed = NULL;
39 #define _pool__malloc malloc
40 #define _pool__free free
56 snprintf(p->zone,
sizeof(p->zone),
"%s:%i", zone, line);
57 sprintf(p->name,
"%X",(
int)p);
59 if(pool__disturbed == NULL)
61 pool__disturbed = (
xht)1;
64 if(pool__disturbed != (
xht)1)
147 fprintf(stderr,
"Memory Leak! [pmalloc received NULL pool, unable to track allocation, exiting]\n");
176 void* result =
pmalloc(p, size);
178 memset(result, c, size);
185 void *block =
pmalloc(p, size);
186 memset(block, 0, size);
198 ret =
pmalloc(p,strlen(src) + 1);
209 if(src == NULL || len <= 0)
221 if(p == NULL)
return 0;
228 struct pfree *cur, *stub;
230 if(p == NULL)
return;
242 if (pool__disturbed != NULL && pool__disturbed != (
xht)1)
261 void _pool_stat(
const char *key,
int keylen,
void *val,
void *
arg)
266 fprintf(stderr,
"POOL: %s: %s is a new pool\n",p->zone,p->name);
267 else if(p->
size > p->lsize)
268 fprintf(stderr,
"POOL: %s: %s grew %d\n",p->zone,p->name, p->
size - p->lsize);
270 fprintf(stderr,
"POOL: %s: %s exists %d\n",p->zone,p->name, p->
size);
276 if (pool__disturbed == NULL || pool__disturbed == (
xht)1)
278 xhash_walk(pool__disturbed,_pool_stat,(
void *)full);
279 if(pool__total != pool__ltotal)
280 fprintf(stderr,
"POOL: %d total missed mallocs\n",pool__total);
281 pool__ltotal = pool__total;
void * pmalloc(pool_t p, int size)
pool_t _pool_new(const char *zone, int line)
make an empty pool
pfree - a linked list node which stores an allocation chunk, plus a callback
void pool_cleanup(pool_t p, pool_cleanup_t f, void *arg)
public cleanup utils, insert in a way that they are run FIFO, before mem frees
static void _pool_heap_free(void *arg)
free a heap
void * pmalloco(pool_t p, int size)
easy safety utility (for creating blank mem for structs, etc)
char * pstrdupx(pool_t p, const char *src, int len)
use given size
void xhash_put(xht h, const char *key, void *val)
struct pool_struct * pool_t
struct pfree * cleanup_tail
void xhash_zap(xht h, const char *key)
static struct pfree * _pool_free(pool_t p, pool_cleanup_t f, void *arg)
create a cleanup tracker
void xhash_walk(xht h, xhash_walker w, void *arg)
void(* pool_cleanup_t)(void *arg)
pool_cleanup_t - callback type which is associated with a pool entry; invoked when the pool entry is ...
static void _pool_cleanup_append(pool_t p, struct pfree *pf)
mem should always be freed last
pheap - singular allocation of memory
char * pstrdup(pool_t p, const char *src)
XXX efficient: move this to const char * and then loop throug the existing heaps to see if src is wit...
pool_t _pool_new_heap(int size, const char *zone, int line)
void * pmalloc_x(pool_t p, int size, char c)
pool - base node for a pool.
static struct pheap * _pool_heap(pool_t p, int size)
create a heap and make sure it get's cleaned up