57 * UCX mempool structure. |
57 * UCX mempool structure. |
58 */ |
58 */ |
59 typedef struct { |
59 typedef struct { |
60 /** List of pointers to pooled memory. */ |
60 /** List of pointers to pooled memory. */ |
61 void **data; |
61 void **data; |
|
62 |
62 /** Count of pooled memory items. */ |
63 /** Count of pooled memory items. */ |
63 size_t ndata; |
64 size_t ndata; |
|
65 |
64 /** Memory pool size. */ |
66 /** Memory pool size. */ |
65 size_t size; |
67 size_t size; |
66 } UcxMempool; |
68 } UcxMempool; |
67 |
69 |
68 /** Shorthand for a new default memory pool with a capacity of 16 elements. */ |
70 /** Shorthand for a new default memory pool with a capacity of 16 elements. */ |
123 * @param elsize amount of memory per element |
125 * @param elsize amount of memory per element |
124 * @return a pointer to the allocated memory |
126 * @return a pointer to the allocated memory |
125 * @see ucx_allocator_calloc() |
127 * @see ucx_allocator_calloc() |
126 */ |
128 */ |
127 void *ucx_mempool_calloc(UcxMempool *pool, size_t nelem, size_t elsize); |
129 void *ucx_mempool_calloc(UcxMempool *pool, size_t nelem, size_t elsize); |
|
130 |
128 /** |
131 /** |
129 * Reallocates pooled memory. |
132 * Reallocates pooled memory. |
130 * |
133 * |
131 * If the memory to be reallocated is not contained by the specified pool, this |
134 * If the memory to be reallocated is not contained by the specified pool, this |
132 * function will possibly fail. In case the memory had to be moved to another |
135 * function will possibly fail. In case the memory had to be moved to another |
138 * @param n the new size of the memory |
141 * @param n the new size of the memory |
139 * @return a pointer to the the location of the memory |
142 * @return a pointer to the the location of the memory |
140 * @see ucx_allocator_realloc() |
143 * @see ucx_allocator_realloc() |
141 */ |
144 */ |
142 void *ucx_mempool_realloc(UcxMempool *pool, void *ptr, size_t n); |
145 void *ucx_mempool_realloc(UcxMempool *pool, void *ptr, size_t n); |
|
146 |
143 /** |
147 /** |
144 * Frees pooled memory. |
148 * Frees pooled memory. |
145 * |
149 * |
146 * Before freeing the memory, the specified destructor function (if any) |
150 * Before freeing the memory, the specified destructor function (if any) |
147 * is called. |
151 * is called. |