| 60 |
60 |
| 61 ```C |
61 ```C |
| 62 #include <cx/mempool.h> |
62 #include <cx/mempool.h> |
| 63 |
63 |
| 64 int cxMempoolTransfer(CxMempool *source, CxMempool *dest); |
64 int cxMempoolTransfer(CxMempool *source, CxMempool *dest); |
| |
65 |
| |
66 int cxMempoolTransferObject(CxMempool *source, CxMempool *dest, |
| |
67 const void *obj); |
| 65 ``` |
68 ``` |
| 66 |
69 |
| 67 Memory managed by a pool can be transferred to another pool. |
70 Memory managed by a pool can be transferred to another pool. |
| 68 |
71 |
| 69 The function `cxMempoolTransfer()` transfers all memory managed and/or registered with the `source` pool to the `dest` pool. |
72 The function `cxMempoolTransfer()` transfers all memory managed and/or registered with the `source` pool to the `dest` pool. |
| 70 It also registers its allocator with the `dest` pool and creates a new allocator for the `source` pool. |
73 It also registers its allocator with the `dest` pool and creates a new allocator for the `source` pool. |
| 71 That means, that all references to the allocator of the `source` pool remain valid and continue to work with the `dest` pool. |
74 That means, that all references to the allocator of the `source` pool remain valid and continue to work with the `dest` pool. |
| 72 The transferred allocator will be destroyed when the `dest` pool gets destroyed. |
75 The transferred allocator will be destroyed when the `dest` pool gets destroyed. |
| 73 |
76 |
| 74 The function returns zero when the transfer was successful and non-zero if a necessary memory allocation was not possible, |
77 The function `cxMempoolTransferObject()` transfers a _single_ object managed by the `source` pool to the `dest` pool. |
| |
78 Memory that was registered with `cxMempoolRegister()` cannot be transferred this way. |
| |
79 Also, if `obj` has a reference to `source->allocator`, it must be updated to `dest->allocator` manually. |
| |
80 |
| |
81 The functions returns zero when the transfer was successful and non-zero if a necessary memory allocation was not possible, |
| 75 or the `source` and `dest` pointers point to the same pool. |
82 or the `source` and `dest` pointers point to the same pool. |
| 76 In case of an error, no memory is transferred and both pools are in a valid state. |
83 In case of an error, no memory is transferred and both pools are in a valid state. |
| 77 |
84 |
| 78 |
85 |
| 79 ## Example |
86 ## Example |