src/cx/mempool.h

changeset 1328
2cf66dee40b8
parent 1325
20caf6efaf07
child 1329
343eac5ac824
--- a/src/cx/mempool.h	Fri May 23 12:44:24 2025 +0200
+++ b/src/cx/mempool.h	Fri May 23 13:36:11 2025 +0200
@@ -43,6 +43,7 @@
 extern "C" {
 #endif
 
+/** A memory block in a simple memory pool. */
 struct cx_mempool_memory_s {
     /** The destructor. */
     cx_destructor_func destructor;
@@ -50,6 +51,7 @@
     char c[];
 };
 
+/** A memory block in an advanced memory pool. */
 struct cx_mempool_memory2_s {
     /** The destructor. */
     cx_destructor_func2 destructor;
@@ -59,6 +61,7 @@
     char c[];
 };
 
+/** Represents memory that is not allocated by, but registered with a pool. */
 struct cx_mempool_foreign_memory_s {
     /** The foreign memory. */
     void* mem;
@@ -170,6 +173,36 @@
 CxMempool *cxMempoolCreate(size_t capacity, enum cx_mempool_type type);
 
 /**
+ * Creates a basic array-based memory pool.
+ *
+ * Convenience macro to create a memory pool of type #CX_MEMPOOL_TYPE_SIMPLE.
+ *
+ * @param capacity (@c size_t) the initial capacity of the pool
+ * @return (@c CxMempool*) the created memory pool or @c NULL if allocation failed
+ */
+#define cxMempoolCreateSimple(capacity) cxMempoolCreate(capacity, CX_MEMPOOL_TYPE_SIMPLE)
+
+/**
+ * Creates a basic array-based memory pool.
+ *
+ * Convenience macro to create a memory pool of type #CX_MEMPOOL_TYPE_ADVANCED.
+ *
+ * @param capacity (@c size_t) the initial capacity of the pool
+ * @return (@c CxMempool*) the created memory pool or @c NULL if allocation failed
+ */
+#define cxMempoolCreateAdvanced(capacity) cxMempoolCreate(capacity, CX_MEMPOOL_TYPE_ADVANCED)
+
+/**
+ * Creates a basic array-based memory pool.
+ *
+ * Convenience macro to create a memory pool of type #CX_MEMPOOL_TYPE_PURE.
+ *
+ * @param capacity (@c size_t) the initial capacity of the pool
+ * @return (@c CxMempool*) the created memory pool or @c NULL if allocation failed
+ */
+#define cxMempoolCreatePure(capacity) cxMempoolCreate(capacity, CX_MEMPOOL_TYPE_PURE)
+
+/**
  * Sets the global destructor for all memory blocks within the specified pool.
  *
  * @param pool the memory pool
@@ -191,14 +224,6 @@
 void cxMempoolGlobalDestructor2(CxMempool *pool, cx_destructor_func2 fnc, void *data);
 
 /**
- * Creates a basic array-based memory pool.
- *
- * @param capacity (@c size_t) the initial capacity of the pool
- * @return (@c CxMempool*) the created memory pool or @c NULL if allocation failed
- */
-#define cxMempoolCreateSimple(capacity) cxMempoolCreate(capacity, CX_MEMPOOL_TYPE_SIMPLE)
-
-/**
  * Sets the destructor function for a specific allocated memory object.
  *
  * If the type of memory pool is not #CX_MEMPOOL_TYPE_SIMPLE, the behavior is undefined.

mercurial