|
CX Framework
Cross-platform C utility framework
|
Macros | |
| #define | saInit(out, type, capacity, ...) _saInit(SAHANDLE(out), stFullType(type), capacity, false, opt_flags(__VA_ARGS__)) |
| #define | saTryInit(out, type, capacity, ...) _saInit(SAHANDLE(out), stFullType(type), capacity, true, opt_flags(__VA_ARGS__)) |
| #define | saDestroy(handle) _saDestroy(SAHANDLE(handle)) |
| #define | saReserve(handle, capacity) _saReserve(SAHANDLE(handle), capacity, true) |
| #define | saShrink(handle, capacity) _saShrink(SAHANDLE(handle), capacity) |
| #define | saSetSize(handle, size) _saSetSize(SAHANDLE(handle), size) |
| #define | saClear(handle) _saClear(SAHANDLE(handle)) |
Array creation, destruction, and capacity/size management operations
| #define saClear | ( | handle | ) | _saClear(SAHANDLE(handle)) |
Removes all elements from the array and sets size to 0
All elements are properly destroyed (unless SA_Ref was used). The allocated capacity is preserved. Safe to call with NULL or uninitialized arrays.
| handle | Pointer to the array |
Example:
| #define saDestroy | ( | handle | ) | _saDestroy(SAHANDLE(handle)) |
void saDestroy(sa_type *handle)
Destroys a dynamic array and frees all associated memory
All elements are properly destroyed according to their type (unless SA_Ref was used). Sets handle->a to NULL after destruction. Safe to call with NULL or uninitialized arrays.
| handle | Pointer to the array |
Example:
| #define saInit | ( | out, | |
| type, | |||
| capacity, | |||
| ... | |||
| ) | _saInit(SAHANDLE(out), stFullType(type), capacity, false, opt_flags(__VA_ARGS__)) |
bool saInit(sa_type *out, type, int32 capacity, [flags])
Initializes a new dynamic array with the specified element type
| out | Pointer to the sarray to initialize |
| type | Runtime type for elements (e.g., int32, string, ptr, object, etc.) |
| capacity | Initial capacity (will be clamped to at least 1, use 0 for default of 8) |
| ... | (flags) Optional combination of SA_* flags:
|
Example:
| #define saReserve | ( | handle, | |
| capacity | |||
| ) | _saReserve(SAHANDLE(handle), capacity, true) |
bool saReserve(sa_type *handle, int32 capacity)
Reserves space for at least the specified capacity
If the current capacity is less than requested, the array is expanded. The array size (number of elements) is not changed, only the allocated capacity.
| handle | Pointer to the array |
| capacity | Minimum capacity to ensure (use 0 for at least 1) |
Example:
| #define saSetSize | ( | handle, | |
| size | |||
| ) | _saSetSize(SAHANDLE(handle), size) |
void saSetSize(sa_type *handle, int32 size)
Sets the array to exactly the specified size
If growing, new elements are zero-initialized. If shrinking, excess elements are properly destroyed. The capacity is automatically adjusted if needed.
| handle | Pointer to the array |
| size | New size for the array |
Example:
| #define saShrink | ( | handle, | |
| capacity | |||
| ) | _saShrink(SAHANDLE(handle), capacity) |
void saShrink(sa_type *handle, int32 capacity)
Reduces the array capacity to free unused memory
Shrinks the allocated capacity to the specified size, but never below the current element count. This is useful for reclaiming memory after removing many elements. Unlike saSetSize, this does not affect the number of elements in the array.
| handle | Pointer to the array |
| capacity | Desired capacity (use 0 for minimum of 1) |
Example:
| #define saTryInit | ( | out, | |
| type, | |||
| capacity, | |||
| ... | |||
| ) | _saInit(SAHANDLE(out), stFullType(type), capacity, true, opt_flags(__VA_ARGS__)) |
bool saTryInit(sa_type *out, type, int32 capacity, [flags])
Same as saInit but can fail and return false if memory allocation fails
| out | Pointer to the sarray to initialize |
| type | Runtime type for elements |
| capacity | Initial capacity |
| ... | (flags) Optional combination of SA_* flags |