docs/Writerside/topics/allocator.h.md

changeset 1694
a2757c6427cc
parent 1539
2cbdb482d325
equal deleted inserted replaced
1693:c2d05cf1a062 1694:a2757c6427cc
101 ```C 101 ```C
102 // when cx_reallocate() fails, mem will still point to the old memory 102 // when cx_reallocate() fails, mem will still point to the old memory
103 if (cx_reallocate(&mem, capacity + 32)) // ... do error handling 103 if (cx_reallocate(&mem, capacity + 32)) // ... do error handling
104 ``` 104 ```
105 105
106 > Please pay special attention to always use `cxFree()` and the `cxRealloc()`-family of functions 106 > Please pay special attention and always use `cxFree()` and the `cxRealloc()`-family of functions
107 > with the **same** allocator that was used to allocate the memory. 107 > with the **same** allocator that was used to allocate the memory.
108 {style="warning"} 108 {style="warning"}
109 109
110 The function `cx_system_page_size()` offers a cross-platform way to retrieve the memory page size in bytes. 110 The function `cx_system_page_size()` offers a cross-platform way to retrieve the memory page size in bytes.
111 If, for some reason, the page size cannot be determined, a default of 4096 bytes is returned. 111 If, for some reason, the page size cannot be determined, a default of 4096 bytes is returned.
156 156
157 typedef void (*cx_destructor_func)(void *memory); 157 typedef void (*cx_destructor_func)(void *memory);
158 typedef void (*cx_destructor_func2)(void *data, void *memory); 158 typedef void (*cx_destructor_func2)(void *data, void *memory);
159 ``` 159 ```
160 160
161 The first one is called _simple_ destructor (e.g. in the context of [collections](collection.h.md)), 161 The first one is called _simple_ destructor (e.g., in the context of [collections](collection.h.md)),
162 and the second one is called _advanced_ destructor. 162 and the second one is called _advanced_ destructor.
163 The only difference is that you can pass additional custom `data` to an advanced destructor function. 163 The only difference is that you can pass additional custom `data` to an advanced destructor function.
164 164
165 Destructor functions play a vital role in deep deallocations. 165 Destructor functions play a vital role in deep deallocations.
166 Another scenario, besides destroying elements in a collection, is the deallocation of objects 166 Another scenario, besides destroying elements in a collection, is the deallocation of objects
224 dst->value = cx_strdup_a(allocator, src->value); 224 dst->value = cx_strdup_a(allocator, src->value);
225 return dst; 225 return dst;
226 } 226 }
227 ``` 227 ```
228 228
229 Clone functions are, for example, used by the functions to clone [lists](list.h.md#clone) or [maps](map.h.md#clone). 229 Clone functions are, for example, used by [lists](list.h.md#clone) or [maps](map.h.md#clone).
230 230
231 <seealso> 231 <seealso>
232 <category ref="apidoc"> 232 <category ref="apidoc">
233 <a href="https://ucx.sourceforge.io/api/allocator_8h.html">allocator.h</a> 233 <a href="https://ucx.sourceforge.io/api/allocator_8h.html">allocator.h</a>
234 </category> 234 </category>

mercurial