48 */ |
48 */ |
49 struct cx_basic_mempool_s { |
49 struct cx_basic_mempool_s { |
50 /** Inherit base structure members. */ |
50 /** Inherit base structure members. */ |
51 CxMempool base; |
51 CxMempool base; |
52 |
52 |
53 /** The underlying allocator. */ |
|
54 CxAllocator *allocator; |
|
55 |
|
56 /** List of pointers to pooled memory. */ |
53 /** List of pointers to pooled memory. */ |
57 void **data; |
54 void **data; |
58 |
55 |
59 /** Number of pooled memory items. */ |
56 /** Number of pooled memory items. */ |
60 size_t ndata; |
57 size_t ndata; |
65 |
62 |
66 /** |
63 /** |
67 * Creates a basic array-based memory pool. |
64 * Creates a basic array-based memory pool. |
68 * |
65 * |
69 * @param capacity the initial capacity of the pool |
66 * @param capacity the initial capacity of the pool |
70 * @param allocator the underlying allocator |
|
71 * @return the created memory pool or \c NULL if allocation failed |
67 * @return the created memory pool or \c NULL if allocation failed |
72 */ |
68 */ |
73 __attribute__((__warn_unused_result__)) |
69 __attribute__((__warn_unused_result__)) |
74 CxMempool *cxBasicMempoolCreate( |
70 CxMempool *cxBasicMempoolCreate(size_t capacity); |
75 size_t capacity, |
|
76 CxAllocator *allocator |
|
77 ); |
|
78 |
|
79 |
|
80 /** |
|
81 * Creates a basic array-based memory pool. |
|
82 * |
|
83 * The pool will use the default standard library allocator. |
|
84 * |
|
85 * @param capacity the initial capacity of the pool |
|
86 * @return the created memory pool or \c NULL if allocation failed |
|
87 */ |
|
88 __attribute__((__warn_unused_result__)) |
|
89 static inline CxMempool *cxBasicMempoolCreateSimple(size_t capacity) { |
|
90 return cxBasicMempoolCreate(capacity, cxDefaultAllocator); |
|
91 } |
|
92 |
71 |
93 #ifdef __cplusplus |
72 #ifdef __cplusplus |
94 } // extern "C" |
73 } // extern "C" |
95 #endif |
74 #endif |
96 |
75 |