ucx/mempool.h

changeset 1
1bcaac272cdf
child 5
88625853ae74
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ucx/mempool.h	Fri Nov 30 21:18:13 2012 +0100
@@ -0,0 +1,48 @@
+/* 
+ *
+ */
+
+#ifndef MPOOL_H
+#define	MPOOL_H
+
+#include "ucx.h"
+#include <stddef.h>
+#include "allocator.h"
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+typedef void(*ucx_destructor)(void*);
+
+typedef struct {
+    void   **data;
+    size_t ndata;
+    size_t size;
+} UcxMempool;
+
+#define UCX_ALLOCATOR_MEMPOOL(pool) {pool, \
+    (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);
+int ucx_mempool_chcap(UcxMempool *pool, size_t newcap);
+
+void *ucx_mempool_malloc(UcxMempool *pool, size_t n);
+void *ucx_mempool_calloc(UcxMempool *pool, size_t nelem, size_t elsize);
+void *ucx_mempool_realloc(UcxMempool *pool, void *ptr, size_t n);
+
+void ucx_mempool_free(UcxMempool *pool);
+
+void ucx_mempool_set_destr(void *ptr, ucx_destructor func);
+void ucx_mempool_reg_destr(UcxMempool *pool, void *ptr, ucx_destructor destr);
+
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif	/* MPOOL_H */
+

mercurial