Fri, 05 Oct 2012 11:52:53 +0200
map can now load values from file into pooled memory
use with care when using a decoder that also allocates memory
1 /*
2 *
3 */
5 #ifndef MPOOL_H
6 #define MPOOL_H
8 #include <stddef.h>
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
14 typedef void(*ucx_destructor)(void*);
16 typedef struct {
17 void **data;
18 size_t ndata;
19 size_t size;
20 } UcxMempool;
22 typedef void*(*ucx_allocator_malloc)(UcxMempool *pool, size_t n);
23 typedef void*(*ucx_allocator_calloc)(UcxMempool *pool, size_t n, size_t size);
24 typedef void*(*ucx_allocator_realloc)(UcxMempool *pool, void *data, size_t n);
26 typedef struct {
27 UcxMempool *pool;
28 ucx_allocator_malloc malloc;
29 ucx_allocator_calloc calloc;
30 ucx_allocator_realloc realloc;
31 } UcxAllocator;
33 #define UCX_ALLOCATOR_DEFAULT {NULL, \
34 ucx_default_malloc, ucx_default_calloc, ucx_default_realloc}
35 #define UCX_ALLOCATOR_MEMPOOL(pool) {pool, \
36 ucx_mempool_malloc, ucx_mempool_calloc, ucx_mempool_realloc}
38 void *ucx_default_malloc(UcxMempool *ignore, size_t n);
39 void *ucx_default_calloc(UcxMempool *ignore, size_t n, size_t size);
40 void *ucx_default_realloc(UcxMempool *ignore, void *data, size_t n);
42 #define ucx_mempool_new_default() ucx_mempool_new(16)
43 UcxMempool *ucx_mempool_new(size_t n);
44 int ucx_mempool_chcap(UcxMempool *pool, size_t newcap);
46 void *ucx_mempool_malloc(UcxMempool *pool, size_t n);
47 void *ucx_mempool_calloc(UcxMempool *pool, size_t nelem, size_t elsize);
48 void *ucx_mempool_realloc(UcxMempool *pool, void *ptr, size_t n);
50 void ucx_mempool_free(UcxMempool *pool);
52 void ucx_mempool_set_destr(void *ptr, ucx_destructor func);
53 void ucx_mempool_reg_destr(UcxMempool *pool, void *ptr, ucx_destructor destr);
56 #ifdef __cplusplus
57 }
58 #endif
60 #endif /* MPOOL_H */