ucx/mempool.h

Fri, 12 Oct 2012 10:54:55 +0200

author
Mike Becker <universe@uap-core.de>
date
Fri, 12 Oct 2012 10:54:55 +0200
changeset 69
fb59270b1de3
parent 50
ff194559eb41
child 103
08018864fb91
permissions
-rw-r--r--

made the code work with VC++ compiler (use make CONF=windows)

olaf@13 1 /*
olaf@13 2 *
olaf@13 3 */
olaf@13 4
olaf@13 5 #ifndef MPOOL_H
olaf@13 6 #define MPOOL_H
olaf@13 7
universe@69 8 #include "ucx.h"
universe@38 9 #include <stddef.h>
universe@50 10 #include "allocator.h"
universe@38 11
olaf@13 12 #ifdef __cplusplus
olaf@13 13 extern "C" {
olaf@13 14 #endif
olaf@13 15
olaf@13 16 typedef void(*ucx_destructor)(void*);
olaf@13 17
olaf@13 18 typedef struct {
olaf@13 19 void **data;
olaf@13 20 size_t ndata;
olaf@13 21 size_t size;
olaf@13 22 } UcxMempool;
olaf@13 23
universe@48 24 #define UCX_ALLOCATOR_MEMPOOL(pool) {pool, \
universe@50 25 (ucx_allocator_malloc) ucx_mempool_malloc, \
universe@50 26 (ucx_allocator_calloc) ucx_mempool_calloc, \
universe@50 27 (ucx_allocator_realloc) ucx_mempool_realloc}
universe@48 28
olaf@13 29 #define ucx_mempool_new_default() ucx_mempool_new(16)
olaf@13 30 UcxMempool *ucx_mempool_new(size_t n);
universe@15 31 int ucx_mempool_chcap(UcxMempool *pool, size_t newcap);
olaf@13 32
olaf@13 33 void *ucx_mempool_malloc(UcxMempool *pool, size_t n);
olaf@13 34 void *ucx_mempool_calloc(UcxMempool *pool, size_t nelem, size_t elsize);
olaf@13 35 void *ucx_mempool_realloc(UcxMempool *pool, void *ptr, size_t n);
olaf@13 36
olaf@13 37 void ucx_mempool_free(UcxMempool *pool);
olaf@13 38
olaf@13 39 void ucx_mempool_set_destr(void *ptr, ucx_destructor func);
olaf@13 40 void ucx_mempool_reg_destr(UcxMempool *pool, void *ptr, ucx_destructor destr);
olaf@13 41
olaf@13 42
olaf@13 43 #ifdef __cplusplus
olaf@13 44 }
olaf@13 45 #endif
olaf@13 46
olaf@13 47 #endif /* MPOOL_H */
olaf@13 48

mercurial