ucx/mempool.h

Fri, 05 Oct 2012 13:23:25 +0200

author
Mike Becker <universe@uap-core.de>
date
Fri, 05 Oct 2012 13:23:25 +0200
changeset 50
ff194559eb41
parent 48
621a4430c404
child 69
fb59270b1de3
permissions
-rw-r--r--

moved allocator to seperate file

function signatures are now "generic" and not restricted to UcxMempool

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

mercurial