CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
xalloc.h File Reference

Extended memory allocation system. More...

#include <cx/platform/cpp.h>
#include <cx/utils/macros/optarg.h>
#include <cx/utils/macros/salieri.h>
#include <cx/utils/macros/unused.h>
#include <stdbool.h>
#include <stddef.h>
#include <cx/xalloc/cstrutil.h>

Go to the source code of this file.

Macros

#define XA_Align(exp)   ((unsigned int)(exp & XA_LG_ALIGN_MASK))
 
#define XA_Zero   ((unsigned int)0x0040)
 Zero-fills returned memory.
 
#define XA_Opt   XA_Optional(High)
 
#define xaAlloc(size, ...)   _xaAlloc(size, opt_flags(__VA_ARGS__))
 
#define xaAllocStruct(typn, ...)   (typn*)_xaAlloc(sizeof(typn), opt_flags(__VA_ARGS__))
 
#define xaResize(ptr, size, ...)    (_xa_ptr_ptr_verify(ptr), _xaResize((void**)(ptr), size, opt_flags(__VA_ARGS__)))
 
#define xaDestroy(ptr)   (_xa_ptr_ptr_verify(ptr), _xaDestroy((void**)(ptr)))
 

Typedefs

typedef void(* xaOOMCallback) (int phase, size_t allocsz)
 

Enumerations

enum  XA_OOM_PHASE_ENUM { XA_LowEffort = 1 , XA_HighEffort , XA_Urgent , XA_Fatal = -1 }
 Phases of out-of-memory handling, indicating escalating urgency. More...
 

Functions

void xaAddOOMCallback (xaOOMCallback cb)
 
void xaRemoveOOMCallback (xaOOMCallback cb)
 
void xaFree (void *ptr)
 
size_t xaSize (void *ptr)
 
size_t xaOptSize (size_t sz)
 
void xaFlush ()
 Flushes any deferred free() operations and returns as much memory to the OS as possible.
 
void * xa_malloc (size_t size)
 malloc-compatible allocation function
 
void * xa_calloc (size_t number, size_t size)
 calloc-compatible allocation function
 
void * xa_realloc (void *ptr, size_t size)
 realloc-compatible allocation function
 
void xa_free (void *ptr)
 free-compatible deallocation function
 
char * xa_strdup (const char *src)
 strdup-compatible string duplication function
 

Detailed Description

Extended memory allocation system.

The xalloc system wraps mimalloc or the system allocator and provides enhanced functionality including alignment, optional allocations, and out-of-memory handling.

Definition in file xalloc.h.