Wed, 30 May 2018 11:13:52 +0200
being more precise on the different required behavior of a destructor function for pooled and non-pooled memory
docs/src/modules.md | file | annotate | diff | comparison | revisions | |
src/ucx/mempool.h | file | annotate | diff | comparison | revisions |
1.1 --- a/docs/src/modules.md Tue May 29 11:05:12 2018 +0200 1.2 +++ b/docs/src/modules.md Wed May 30 11:13:52 2018 +0200 1.3 @@ -455,6 +455,10 @@ 1.4 Be aware, that your destructor function should not free any memory, that is 1.5 also managed by the pool. 1.6 Otherwise you might be risking a double-free. 1.7 +More precisely, a destructor function set with `ucx_mempool_set_destr()` MUST 1.8 +NOT call `free()` on the specified pointer whereas a desructor function 1.9 +registered with `ucx_mempool_reg_destr()` MAY (and in most cases will) call 1.10 +`free()`. 1.11 1.12 ## Properties 1.13
2.1 --- a/src/ucx/mempool.h Tue May 29 11:05:12 2018 +0200 2.2 +++ b/src/ucx/mempool.h Wed May 30 11:13:52 2018 +0200 2.3 @@ -164,6 +164,9 @@ 2.4 * 2.5 * The destructor is automatically called when the memory is freed or the 2.6 * pool is destroyed. 2.7 + * A destructor for pooled memory <b>MUST NOT</b> free the memory itself, 2.8 + * as this is done by the pool. Use a destructor to free any resources 2.9 + * managed by the pooled object. 2.10 * 2.11 * The only requirement for the specified memory is, that it <b>MUST</b> be 2.12 * pooled memory by a UcxMempool or an element-compatible mempool. The pointer 2.13 @@ -179,12 +182,18 @@ 2.14 2.15 /** 2.16 * Registers a destructor function for the specified (non-pooled) memory. 2.17 - * 2.18 + * 2.19 * This is useful, if you have memory that has not been allocated by a mempool, 2.20 * but shall be managed by a mempool. 2.21 * 2.22 * This function creates an entry in the specified mempool and the memory will 2.23 * therefore (logically) convert to pooled memory. 2.24 + * <b>However, this does not cause the memory to be freed automatically!</b>. 2.25 + * If you want to use this function, make the memory pool free non-pooled 2.26 + * memory, the specified destructor function must call <code>free()</code> 2.27 + * by itself. But keep in mind, that you then MUST NOT use this destructor 2.28 + * function with pooled memory (e.g. in ucx_mempool_set_destr()), as it 2.29 + * would cause a double-free. 2.30 * 2.31 * @param pool the memory pool 2.32 * @param ptr data the destructor is registered for