9#include <cx/platform/cpp.h>
11#include <cx/utils/macros/salieri.h>
16#ifdef XALLOC_REMAP_MALLOC
24#undef _CRTDBG_MAP_ALLOC
83#define XA_LG_ALIGN_MASK ((unsigned int)0x3f)
88#define XA_Align(exp) ((unsigned int)(exp & XA_LG_ALIGN_MASK))
91#define XA_Zero ((unsigned int)0x0040)
93enum XA_OPTIONAL_FLAG_ENUM {
94 XA_Optional_High = 0x0100,
95 XA_Optional_Low = 0x0200,
96 XA_Optional_None = 0x0400
98#define XA_Optional(typ) ((unsigned int)XA_Optional_##typ)
99#define XA_Optional_Mask (XA_Optional_High | XA_Optional_Low | XA_Optional_None)
109#define XA_Opt XA_Optional(High)
154#define _xa_ptr_ptr_verify(ptr) unused_noeval(&*(*(ptr)))
158#define _xa_ptr_ptr_verify(ptr) unused_noeval((void*)(*(ptr)))
199#define xaAlloc(size, ...) _xaAlloc(size, opt_flags(__VA_ARGS__))
213#define xaAllocStruct(typn, ...) (typn*)_xaAlloc(sizeof(typn), opt_flags(__VA_ARGS__))
215_Check_return_ _When_(flags & XA_Optional_Mask, _Must_inspect_result_ _Ret_maybenull_)
216 _When_(!(flags & XA_Optional_Mask), _Ret_notnull_)
217 _When_(!(flags & XA_Optional_Mask) && (flags &
XA_Zero), _Ret_valid_)
218 _Post_writable_byte_size_(size)
void* _xaAlloc(
size_t size,
unsigned int flags);
229#define xaResize(ptr, size, ...) \
230 (_xa_ptr_ptr_verify(ptr), _xaResize((void**)(ptr), size, opt_flags(__VA_ARGS__)))
231_At_(*ptr, _Pre_maybenull_) _When_(
233 XA_Optional_Mask), _At_(*ptr, _Post_writable_byte_size_(size)) )
bool _xaResize(_Inout_
void** ptr,
size_t size,
unsigned int flags);
238void xaFree(_Pre_maybenull_ _Post_invalid_
void* ptr);
246#define xaDestroy(ptr) (_xa_ptr_ptr_verify(ptr), _xaDestroy((void**)(ptr)))
247_At_(*ptr, _Pre_maybenull_ _Post_null_)
bool _xaDestroy(_Inout_
void** ptr);
297#ifdef XALLOC_REMAP_MALLOC
298#define malloc(sz) xa_malloc(sz)
299#define calloc(num, sz) xa_calloc(num, sz)
300#define free(ptr) xa_free(ptr)
301#define realloc(ptr, sz) xa_realloc(ptr, sz)
302#define strdup(s) cstrDup(s)
303#define _strdup(s) cstrDup(s)
304#define wcsdup(s) cstrDupw(s)
305#define _wcsdup(s) cstrDupw(s)
309#define _malloc_dbg(sz, t, f, ln) xa_malloc(sz)
311#define _calloc_dbg(num, sz, t, f, ln) xa_calloc(num, sz)
313#define _free_dbg(ptr, t) xa_free(ptr)
315#define _realloc_dbg(ptr, sz, t, f, ln) xa_realloc(ptr, sz)
317#define _strdup_dbg(s, t, f, ln) cstrDup(s)
319#define _wcsdup_dbg(s, t, f, ln) cstrDupw(s)
336#ifdef XALLOC_COMPAT_REQUIRE
337#define XA_COMPAT_OPT_FLAG 0
339#define XA_COMPAT_OPT_FLAG XA_Opt
346 return _xaAlloc(size, XA_COMPAT_OPT_FLAG);
352 return _xaAlloc(number * size,
XA_Zero | XA_COMPAT_OPT_FLAG);
358 return _xaResize(&ptr, size, XA_COMPAT_OPT_FLAG) ? ptr : (
void*)0;
C string utility functions.
char * cstrDup(const char *s)
char * xa_strdup(const char *src)
strdup-compatible string duplication function
void * xa_realloc(void *ptr, size_t size)
realloc-compatible allocation function
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_free(void *ptr)
free-compatible deallocation function
#define XA_Zero
Zero-fills returned memory.
size_t xaOptSize(size_t sz)
void(* xaOOMCallback)(int phase, size_t allocsz)
void xaRemoveOOMCallback(xaOOMCallback cb)
void xaAddOOMCallback(xaOOMCallback cb)
XA_OOM_PHASE_ENUM
Phases of out-of-memory handling, indicating escalating urgency.
void xaFlush()
Flushes any deferred free() operations and returns as much memory to the OS as possible.
Optional macro argument handling.
Copy-on-write strings with automatic memory management and rope optimization.
Macros for suppressing compiler warnings.