--- a/docs/Writerside/topics/allocator.h.md Thu May 15 15:43:30 2025 +0200 +++ b/docs/Writerside/topics/allocator.h.md Thu May 15 16:02:54 2025 +0200 @@ -4,11 +4,18 @@ that can also be used in many other function in UCX. A default allocator implementation using the stdlib functions is -available via the global symbol `cxDefaultAllocator` +available via the global symbol `cxStdlibAllocator`, and UCX also provides a [memory pool](mempool.h.md) implementation. -You are free to add additional own custom implementations. +You are free to add your additional, own custom implementations. A general sketch that illustrates how to do this can be found [below](#custom-allocator). +## Default Allocator + +The global default allocator which is used by UCX, +when no specific allocator is specified, +can be configured via the `cxDefaultAllocator`. +It is by default set to the `cxStdlibAllocator`. + ## Overview ```C @@ -36,12 +43,19 @@ int cx_reallocatearray(void **mem, size_t nmemb, size_t size); // predefined allocator that uses stdlib functions -CxAllocator *cxDefaultAllocator; +CxAllocator * const cxStdlibAllocator; + +// default allocator that can be changed +CxAllocator *cxDefaultAllocator = cxStdlibAllocator; ``` > All UCX functions that are not _explicitly_ designed for taking an allocator argument > (recognizable by a `_a` suffix in the function's name) do support a `NULL` argument > in which case the `cxDefaultAllocator` will be used. +> +> You may change the default allocator at any time, but it is strongly recommended to +> do it only once at program start to avoid accidentally freeing memory that was +> allocated by a different allocator. ## Description