33#ifndef UCX_ALLOCATOR_H
34#define UCX_ALLOCATOR_H
45 void *(*malloc)(
void *data,
size_t n);
50 void *(*realloc)(
void *data,
void *mem,
size_t n);
55 void *(*calloc)(
void *data,
size_t nmemb,
size_t size);
60 void (*
free)(
void *data,
void *mem);
141typedef void*(*cx_clone_func)(
void *target,
const void *source,
199#define cx_reallocate(mem, n) cx_reallocate_((void**)(mem), n)
219#define cx_reallocatearray(mem, nmemb, size) \
220 cx_reallocatearray_((void**)(mem), nmemb, size)
228#define cx_zalloc(n) calloc(1, n)
294 void *mem,
size_t nmemb,
size_t size);
326#define cxReallocate(allocator, mem, n) \
327 cxReallocate_(allocator, (void**)(mem), n)
343 void **mem,
size_t nmemb,
size_t size);
364#define cxReallocateArray(allocator, mem, nmemb, size) \
365 cxReallocateArray_(allocator, (void**) (mem), nmemb, size)
398#define cxMallocDefault(n) cxMalloc(cxDefaultAllocator, n)
408#define cxZallocDefault(n) cxZalloc(cxDefaultAllocator, n)
419#define cxCallocDefault(nmemb, size) cxCalloc(cxDefaultAllocator, nmemb, size)
435#define cxReallocDefault(mem, n) cxRealloc(cxDefaultAllocator, mem, n)
454#define cxReallocateDefault(mem, n) cxReallocate(cxDefaultAllocator, mem, n)
476#define cxReallocateArrayDefault(mem, nmemb, size) \
477 cxReallocateArray(cxDefaultAllocator, mem, nmemb, size)
500#define cxReallocArrayDefault(mem, nmemb, size) cxReallocArray(cxDefaultAllocator, mem, nmemb, size)
unsigned long cx_system_page_size(void)
Returns the system's memory page size.
int cxReallocate_(const CxAllocator *allocator, void **mem, size_t n)
Reallocate a previously allocated block.
void(* cx_destructor_func2)(void *data, void *memory)
Function pointer type for destructor functions.
Definition allocator.h:116
int cx_reallocatearray_(void **mem, size_t nmemb, size_t size)
Reallocate a previously allocated block.
struct cx_allocator_s CxAllocator
High-Level type alias for the allocator type.
Definition allocator.h:80
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:103
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.
int cx_reallocate_(void **mem, size_t n)
Reallocate a previously allocated block.
void * cxCalloc(const CxAllocator *allocator, size_t nmemb, size_t size)
Allocate nmemb elements of size 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.
void cxFreeDefault(void *mem)
Free a block of memory.
int cxReallocateArray_(const CxAllocator *allocator, void **mem, size_t nmemb, size_t size)
Reallocate a previously allocated block.
const CxAllocator *const cxStdlibAllocator
A pre-defined allocator using standard library malloc() etc.
Common definitions and feature checks.
#define CX_MALLOC
The attributed function always returns freshly allocated memory.
Definition common.h:156
#define CX_EXPORT
Only used for building Windows DLLs.
Definition common.h:289
#define CX_NONNULL
All pointer arguments must be non-NULL.
Definition common.h:141
#define CX_NODISCARD
Warn about discarded return value.
Definition common.h:256
#define CX_NONNULL_ARG(...)
The specified pointer arguments must be non-NULL.
Definition common.h:146
#define CX_EXTERN
Declares a function with external linkage.
Definition common.h:297
#define CX_DEALLOC_UCX
Shortcut to specify cxFree() as deallocator.
Definition common.h:178
#define CX_ALLOCSIZE(...)
Specifies the parameters from which the allocation size is calculated.
Definition common.h:183
The class definition for an allocator.
Definition allocator.h:41
void(* free)(void *data, void *mem)
The allocator's free() implementation.
Definition allocator.h:60
Structure holding the data for an allocator.
Definition allocator.h:66
void * data
A pointer to the data this allocator uses.
Definition allocator.h:74
cx_allocator_class * cl
A pointer to the instance of the allocator class.
Definition allocator.h:70