src/ucx/mempool.h

changeset 326
3dd7d21fb76b
parent 259
2f5dea574a75
equal deleted inserted replaced
325:a3e63cb21e20 326:3dd7d21fb76b
162 /** 162 /**
163 * Sets a destructor function for the specified memory. 163 * Sets a destructor function for the specified memory.
164 * 164 *
165 * The destructor is automatically called when the memory is freed or the 165 * The destructor is automatically called when the memory is freed or the
166 * pool is destroyed. 166 * pool is destroyed.
167 * A destructor for pooled memory <b>MUST NOT</b> free the memory itself,
168 * as this is done by the pool. Use a destructor to free any resources
169 * managed by the pooled object.
167 * 170 *
168 * The only requirement for the specified memory is, that it <b>MUST</b> be 171 * The only requirement for the specified memory is, that it <b>MUST</b> be
169 * pooled memory by a UcxMempool or an element-compatible mempool. The pointer 172 * pooled memory by a UcxMempool or an element-compatible mempool. The pointer
170 * to the destructor function is saved in a reserved area before the actual 173 * to the destructor function is saved in a reserved area before the actual
171 * memory. 174 * memory.
177 */ 180 */
178 void ucx_mempool_set_destr(void *ptr, ucx_destructor func); 181 void ucx_mempool_set_destr(void *ptr, ucx_destructor func);
179 182
180 /** 183 /**
181 * Registers a destructor function for the specified (non-pooled) memory. 184 * Registers a destructor function for the specified (non-pooled) memory.
182 * 185 *
183 * This is useful, if you have memory that has not been allocated by a mempool, 186 * This is useful, if you have memory that has not been allocated by a mempool,
184 * but shall be managed by a mempool. 187 * but shall be managed by a mempool.
185 * 188 *
186 * This function creates an entry in the specified mempool and the memory will 189 * This function creates an entry in the specified mempool and the memory will
187 * therefore (logically) convert to pooled memory. 190 * therefore (logically) convert to pooled memory.
191 * <b>However, this does not cause the memory to be freed automatically!</b>.
192 * If you want to use this function, make the memory pool free non-pooled
193 * memory, the specified destructor function must call <code>free()</code>
194 * by itself. But keep in mind, that you then MUST NOT use this destructor
195 * function with pooled memory (e.g. in ucx_mempool_set_destr()), as it
196 * would cause a double-free.
188 * 197 *
189 * @param pool the memory pool 198 * @param pool the memory pool
190 * @param ptr data the destructor is registered for 199 * @param ptr data the destructor is registered for
191 * @param destr a pointer to the destructor function 200 * @param destr a pointer to the destructor function
192 */ 201 */

mercurial