Fri, 05 Oct 2012 13:23:25 +0200
moved allocator to seperate file
function signatures are now "generic" and not restricted to UcxMempool
ucx/Makefile | file | annotate | diff | comparison | revisions | |
ucx/allocator.c | file | annotate | diff | comparison | revisions | |
ucx/allocator.h | file | annotate | diff | comparison | revisions | |
ucx/mempool.c | file | annotate | diff | comparison | revisions | |
ucx/mempool.h | file | annotate | diff | comparison | revisions |
--- a/ucx/Makefile Fri Oct 05 11:55:36 2012 +0200 +++ b/ucx/Makefile Fri Oct 05 13:23:25 2012 +0200 @@ -29,7 +29,7 @@ include ../$(CONF).mk # list of source files -SRC = list.c dlist.c map.c mempool.c string.c test.c +SRC = list.c dlist.c map.c mempool.c string.c test.c allocator.c OBJ = $(SRC:%.c=../build/%.$(OBJ_EXT))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ucx/allocator.c Fri Oct 05 13:23:25 2012 +0200 @@ -0,0 +1,12 @@ +#include "allocator.h" +#include <stdlib.h> + +void *ucx_default_malloc(void *ignore, size_t n) { + return malloc(n); +} +void *ucx_default_calloc(void *ignore, size_t n, size_t size) { + return calloc(n, size); +} +void *ucx_default_realloc(void *ignore, void *data, size_t n) { + return realloc(data, n); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ucx/allocator.h Fri Oct 05 13:23:25 2012 +0200 @@ -0,0 +1,32 @@ +#ifndef ALLOCATOR_H +#define ALLOCATOR_H + +#include <stddef.h> + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void*(*ucx_allocator_malloc)(void *pool, size_t n); +typedef void*(*ucx_allocator_calloc)(void *pool, size_t n, size_t size); +typedef void*(*ucx_allocator_realloc)(void *pool, void *data, size_t n); + +typedef struct { + void *pool; + ucx_allocator_malloc malloc; + ucx_allocator_calloc calloc; + ucx_allocator_realloc realloc; +} UcxAllocator; + +void *ucx_default_malloc(void *ignore, size_t n); +void *ucx_default_calloc(void *ignore, size_t n, size_t size); +void *ucx_default_realloc(void *ignore, void *data, size_t n); + +#define UCX_ALLOCATOR_DEFAULT {NULL, \ + ucx_default_malloc, ucx_default_calloc, ucx_default_realloc} + +#ifdef __cplusplus +} +#endif + +#endif /* ALLOCATOR_H */
--- a/ucx/mempool.c Fri Oct 05 11:55:36 2012 +0200 +++ b/ucx/mempool.c Fri Oct 05 13:23:25 2012 +0200 @@ -24,16 +24,6 @@ rd->destructor(rd->ptr); } -void *ucx_default_malloc(UcxMempool *ignore, size_t n) { - return malloc(n); -} -void *ucx_default_calloc(UcxMempool *ignore, size_t n, size_t size) { - return calloc(n, size); -} -void *ucx_default_realloc(UcxMempool *ignore, void *data, size_t n) { - return realloc(data, n); -} - UcxMempool *ucx_mempool_new(size_t n) { UcxMempool *pool = (UcxMempool*)malloc(sizeof(UcxMempool)); if (pool == NULL) return NULL;
--- a/ucx/mempool.h Fri Oct 05 11:55:36 2012 +0200 +++ b/ucx/mempool.h Fri Oct 05 13:23:25 2012 +0200 @@ -6,6 +6,7 @@ #define MPOOL_H #include <stddef.h> +#include "allocator.h" #ifdef __cplusplus extern "C" { @@ -19,25 +20,10 @@ size_t size; } UcxMempool; -typedef void*(*ucx_allocator_malloc)(UcxMempool *pool, size_t n); -typedef void*(*ucx_allocator_calloc)(UcxMempool *pool, size_t n, size_t size); -typedef void*(*ucx_allocator_realloc)(UcxMempool *pool, void *data, size_t n); - -typedef struct { - UcxMempool *pool; - ucx_allocator_malloc malloc; - ucx_allocator_calloc calloc; - ucx_allocator_realloc realloc; -} UcxAllocator; - -#define UCX_ALLOCATOR_DEFAULT {NULL, \ - ucx_default_malloc, ucx_default_calloc, ucx_default_realloc} #define UCX_ALLOCATOR_MEMPOOL(pool) {pool, \ - ucx_mempool_malloc, ucx_mempool_calloc, ucx_mempool_realloc} - -void *ucx_default_malloc(UcxMempool *ignore, size_t n); -void *ucx_default_calloc(UcxMempool *ignore, size_t n, size_t size); -void *ucx_default_realloc(UcxMempool *ignore, void *data, size_t n); + (ucx_allocator_malloc) ucx_mempool_malloc, \ + (ucx_allocator_calloc) ucx_mempool_calloc, \ + (ucx_allocator_realloc) ucx_mempool_realloc} #define ucx_mempool_new_default() ucx_mempool_new(16) UcxMempool *ucx_mempool_new(size_t n);