From 4308cd4abe5a75fb8410df929eac687cbd04032b Mon Sep 17 00:00:00 2001 From: kartofen Date: Sun, 8 Sep 2024 18:36:07 +0300 Subject: update mempool and add implement hash array mapped trie (not integrated) --- src/mempool.h | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'src/mempool.h') diff --git a/src/mempool.h b/src/mempool.h index 6c25ac9..7d065f5 100644 --- a/src/mempool.h +++ b/src/mempool.h @@ -1,13 +1,11 @@ #ifndef MEMPOOL_H #define MEMPOOL_H -#ifndef MEMPOOL_OBJ_TYPE -#define MEMPOOL_OBJ_TYPE int -#endif - -#ifndef MEMPOOL_CAP -#define MEMPOOL_CAP (1 << 16) -#endif +/* To generate use MEMPOOL_GENERATE(id, type, cap), where functions + * _mempool_allocate() and _mempool_free(type *obj) will be prefixed with id + * and can be used to allocate objects of type with objects in + * each block + */ #define for_each_block(id, b, head) \ for(struct id##_block *b = (head), *next = NULL; \ @@ -15,13 +13,13 @@ #define get_last_block(b) \ while((b)->next != NULL) (b) = (b)->next -#define MEMPOOL_GENERATE(id) \ +#define MEMPOOL_GENERATE(id, type, cap) \ \ struct id##_block { \ union id##_chunk { \ - MEMPOOL_OBJ_TYPE obj; \ + type obj; \ union id##_chunk *next; \ - } chunks[MEMPOOL_CAP]; \ + } chunks[cap]; \ \ struct id##_block *next; \ }; \ @@ -33,9 +31,9 @@ static inline void *_##id##_mempool_init_block(struct id##_block *b) \ { \ b->next = NULL; \ - for(size_t i = 0; i < MEMPOOL_CAP; i++) \ + for(size_t i = 0; i < cap; i++) \ b->chunks[i].next = &b->chunks[i+1]; \ - b->chunks[MEMPOOL_CAP-1].next = NULL; \ + b->chunks[cap-1].next = NULL; \ \ return b->chunks; \ } \ -- cgit v1.2.3