commit 686b4ac9f8b02c9cab13952365e5fd1b4406c999
parent c2b5067c010580f1e85c10f15ab3476494837024
Author: MikoĊaj Lenczewski <mblenczewski@gmail.com>
Date: Sun, 12 Feb 2023 02:47:02 +0000
Introduce helper macros for mem_pool_init() and mem_pool_alloc()
Diffstat:
1 file changed, 6 insertions(+), 0 deletions(-)
diff --git a/include/utils.h b/include/utils.h
@@ -114,6 +114,9 @@ mem_pool_init(struct mem_pool *self, u64 alignment, u64 capacity) {
return true;
}
+#define MEM_POOL_INIT(pool, type, capacity) \
+mem_pool_init((pool), alignof(type), (capacity) * sizeof(type))
+
static inline void
mem_pool_free(struct mem_pool *self) {
assert(self);
@@ -158,6 +161,9 @@ mem_pool_alloc(struct mem_pool *self, u64 alignment, u64 size) {
return ptr;
}
+#define MEM_POOL_ALLOC(pool, type, count) \
+(type *)mem_pool_alloc((pool), alignof(type), (count) * sizeof(type))
+
#ifdef __cplusplus
};
#endif /* __cplusplus */