33#ifndef UCX_ALLOCATOR_H
34#define UCX_ALLOCATOR_H
49 void *(*malloc)(
void *data,
size_t n);
54 void *(*realloc)(
void *data,
void *mem,
size_t n);
59 void *(*calloc)(
void *data,
size_t nmemb,
size_t size);
64 void (*
free)(
void *data,
void *mem);
203#define cx_reallocate(mem, n) cx_reallocate_((void**)(mem), n)
223#define cx_reallocatearray(mem, nmemb, size) \
224 cx_reallocatearray_((void**)(mem), nmemb, size)
232#define cx_zalloc(n) calloc(1, n)
294 void *mem,
size_t nmemb,
size_t size);
331#define cxReallocate(allocator, mem, n) \
332 cxReallocate_(allocator, (void**)(mem), n)
355 void **mem,
size_t nmemb,
size_t size);
376#define cxReallocateArray(allocator, mem, nmemb, size) \
377 cxReallocateArray_(allocator, (void**) (mem), nmemb, size)
405#define cxMallocDefault(...) cxMalloc(cxDefaultAllocator, __VA_ARGS__)
409#define cxZallocDefault(...) cxZalloc(cxDefaultAllocator, __VA_ARGS__)
413#define cxCallocDefault(...) cxCalloc(cxDefaultAllocator, __VA_ARGS__)
417#define cxReallocDefault(...) cxRealloc(cxDefaultAllocator, __VA_ARGS__)
421#define cxReallocateDefault(...) cxReallocate(cxDefaultAllocator, __VA_ARGS__)
425#define cxReallocateArrayDefault(...) cxReallocateArray(cxDefaultAllocator, __VA_ARGS__)
429#define cxReallocArrayDefault(...) cxReallocArray(cxDefaultAllocator, __VA_ARGS__)
433#define cxFreeDefault(...) cxFree(cxDefaultAllocator, __VA_ARGS__)
int cxReallocate_(const CxAllocator *allocator, void **mem, size_t n)
Reallocate a previously allocated block and changes the pointer in-place, if necessary.
void(* cx_destructor_func2)(void *data, void *memory)
Function pointer type for destructor functions.
Definition allocator.h:120
int cx_reallocatearray_(void **mem, size_t nmemb, size_t size)
Reallocate a previously allocated block and changes the pointer in-place, if necessary.
struct cx_allocator_s CxAllocator
High-Level type alias for the allocator type.
Definition allocator.h:84
void cxFree(const CxAllocator *allocator, void *mem)
Free a block allocated by this allocator.
const CxAllocator * cxDefaultAllocator
The default allocator that is used by UCX.
void * cxZalloc(const CxAllocator *allocator, size_t n)
Allocate n bytes of memory and sets every byte to zero.
void(* cx_destructor_func)(void *memory)
Function pointer type for destructor functions.
Definition allocator.h:107
void * cxMalloc(const CxAllocator *allocator, size_t n)
Allocate n bytes of memory.
void * cxReallocArray(const CxAllocator *allocator, void *mem, size_t nmemb, size_t size)
Reallocate the previously allocated block in mem, making the new block n bytes long.
int cx_reallocate_(void **mem, size_t n)
Reallocate a previously allocated block and changes the pointer in-place, if necessary.
void * cxCalloc(const CxAllocator *allocator, size_t nmemb, size_t size)
Allocate nmemb elements of n bytes each, all initialized to zero.
void * cxRealloc(const CxAllocator *allocator, void *mem, size_t n)
Reallocate the previously allocated block in mem, making the new block n bytes long.
int cxReallocateArray_(const CxAllocator *allocator, void **mem, size_t nmemb, size_t size)
Reallocate a previously allocated block and changes the pointer in-place, if necessary.
const CxAllocator *const cxStdlibAllocator
A pre-defined allocator using standard library malloc() etc.
void * cx_clone_func(void *target, const void *source, const CxAllocator *allocator, void *data)
Function pointer type for clone functions.
Definition allocator.h:145
Common definitions and feature checks.
#define cx_attr_allocsize(...)
Specifies the parameters from which the allocation size is calculated.
Definition common.h:183
#define cx_attr_nonnull
All pointer arguments must be non-NULL.
Definition common.h:141
#define CX_EXPORT
Only used for building Windows DLLs.
Definition common.h:278
#define cx_attr_nodiscard
Warn about discarded return value.
Definition common.h:256
#define cx_attr_malloc
The attributed function always returns freshly allocated memory.
Definition common.h:156
#define cx_attr_dealloc_ucx
Shortcut to specify cxFree() as deallocator.
Definition common.h:178
#define cx_attr_nonnull_arg(...)
The specified pointer arguments must be non-NULL.
Definition common.h:146
The class definition for an allocator.
Definition allocator.h:45
void(* free)(void *data, void *mem)
The allocator's free() implementation.
Definition allocator.h:64
Structure holding the data for an allocator.
Definition allocator.h:70
void * data
A pointer to the data this allocator uses.
Definition allocator.h:78
cx_allocator_class * cl
A pointer to the instance of the allocator class.
Definition allocator.h:74