CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
Core Allocation Functions

Macros

#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)))
 

Functions

void xaFree (void *ptr)
 

Detailed Description

Primary memory allocation and deallocation functions.

Macro Definition Documentation

◆ xaAlloc

#define xaAlloc (   size,
  ... 
)    _xaAlloc(size, opt_flags(__VA_ARGS__))

void *xaAlloc(size_t size, [flags])

Allocate memory of at least size bytes.

Flags can be combined:

  • XA_Align(exp) - Align to 2^exp byte boundary
  • XA_Zero - Zero-fill the memory
  • XA_Optional(tier) or XA_Opt - Allow allocation to fail
Parameters
sizeNumber of bytes to allocate
...(flags) Optional allocation flags
Returns
Pointer to allocated memory, or NULL if optional and out of memory

Definition at line 199 of file xalloc.h.

◆ xaAllocStruct

#define xaAllocStruct (   typn,
  ... 
)    (typn*)_xaAlloc(sizeof(typn), opt_flags(__VA_ARGS__))

typename *xaAllocStruct(typn, [flags])

Convenience macro to allocate a struct-sized block of memory.

Flags can be combined:

  • XA_Align(exp) - Align to 2^exp byte boundary
  • XA_Zero - Zero-fill the memory
  • XA_Optional(tier) or XA_Opt - Allow allocation to fail
Parameters
typnType name of the struct to allocate
...(flags) Optional allocation flags
Returns
Pointer to allocated memory of the specified type

Definition at line 213 of file xalloc.h.

◆ xaDestroy

#define xaDestroy (   ptr)    (_xa_ptr_ptr_verify(ptr), _xaDestroy((void**)(ptr)))

bool xaDestroy(void **ptr)

Destroys the pointer. This frees *ptr (if it is non-NULL) and sets it to NULL.

Parameters
ptrPointer to pointer to free and set to NULL
Returns
Always returns true

Definition at line 246 of file xalloc.h.

◆ xaResize

#define xaResize (   ptr,
  size,
  ... 
)     (_xa_ptr_ptr_verify(ptr), _xaResize((void**)(ptr), size, opt_flags(__VA_ARGS__)))

bool xaResize(void **ptr, size_t size, [flags])

Reallocate ptr to be at least size bytes large, copying it if necessary. If ptr points to NULL, allocates new memory.

Parameters
ptrPointer to pointer to reallocate
sizeNew size in bytes
...(flags) Optional allocation flags (XA_Opt to allow failure)
Returns
True if successfully resized and ptr updated, false on failure (if XA_Opt is set)

Definition at line 229 of file xalloc.h.

Function Documentation

◆ xaFree()

void xaFree ( void *  ptr)

Frees the memory at ptr. Does nothing if ptr is NULL.

Parameters
ptrPointer to memory to free

Referenced by xa_free().