|
CX Framework
Cross-platform C utility framework
|
Macros | |
| #define | saDeclareType(name, typ) |
| #define | saDeclare(name) saDeclareType(name, name) |
| #define | saDeclarePtr(name) saDeclareType(name, name*) |
| #define | saInitNone { .a = 0 } |
| #define | SA_Grow(rate) (((uint32)SA_GROW_##rate) << 24) |
| #define | saSize(ref) ((ref)._is_sarray ? _saHdr(SAREF(ref))->count : 0) |
| #define | saCapacity(ref) ((ref)._is_sarray ? _saHdr(SAREF(ref))->capacity : 0) |
| #define | saElemSize(ref) ((ref)._is_sarray ? stGetSize(_saHdr(SAREF(ref))->elemtype) : 0) |
| #define | saElemType(ref) ((ref)._is_sarray ? _saHdr(SAREF(ref))->elemtype : 0) |
| #define | saValid(ref) ((ref).a) |
Enumerations | |
| enum | SARRAY_CREATE_FLAGS_ENUM { SA_Ref = 0x0010 , SA_Sorted = 0x0020 , SA_AutoShrink = 0x0040 , SAINT_Extended = 0x8000 } |
| Creation flags for sarray initialization. More... | |
| enum | SARRAY_FUNC_FLAGS_ENUM { SA_Unique = 0x00010000 , SA_Fast = 0x00020000 , SA_Inexact = 0x00100000 , SAINT_Consume = 0x10000000 } |
| Operation flags for sarray functions. More... | |
Array type declarations, pre-defined types, and information queries
Type System Overview:
Each distinct element type requires its own sarray type declaration (e.g., sa_int32, sa_string). These types are declared using the saDeclareType() or convenience macros like saDeclare(). Common types are pre-declared below.
The .a member provides direct typed access to the array's data:
This design enables compile-time type checking while maintaining the flexibility of generic operations through the runtime type system.
| #define SA_Grow | ( | rate | ) | (((uint32)SA_GROW_##rate) << 24) |
Converts a growth rate to the format used in the flags parameter
Controls how the array capacity expands when more space is needed. Dynamic rates automatically adjust growth as the array gets larger to balance performance with memory efficiency.
Available rates:
Dynamic Growth (Recommended):
| Rate | Initial | Mid-size | Large | Thresholds | Use Case |
|---|---|---|---|---|---|
| Auto | Varies | Varies | Varies | Element-size based | Automatic selection (default) |
| Normal | 100% | 50% | 25% | 16→128 elements | Balanced default for most cases |
| Aggressive | 100% | 50% | 25% | 32→256 elements | Better performance, more memory |
| Slow | 100% | 50% | 25% | 8→64 elements | Memory efficient, slower growth |
Fixed Growth Rates:
| Rate | Multiplier | Use Case |
|---|---|---|
| 100 | 2x | Always double capacity (fast growth) |
| 50 | 1.5x | Moderate growth |
| 25 | 1.25x | Conservative growth |
| Minimal | Exact | No over-allocation (slowest, minimal memory) |
Dynamic rates start with high growth for small arrays, then reduce the rate as the array grows larger. This provides good performance for typical usage while avoiding excessive memory consumption for large arrays.
| rate | Growth rate (e.g., Auto, Normal, Aggressive, 100, 50, Minimal) |
| #define saCapacity | ( | ref | ) | ((ref)._is_sarray ? _saHdr(SAREF(ref))->capacity : 0) |
Returns the allocated capacity of the array
| ref | The array (passed by value) |
| #define saDeclare | ( | name | ) | saDeclareType(name, name) |
Declares a named sarray type where the element type matches the name
| name | The type name (both for array and element) |
| #define saDeclarePtr | ( | name | ) | saDeclareType(name, name*) |
Declares a named sarray type for pointer-to-name elements
| name | The base type name (creates array of name*) |
| #define saDeclareType | ( | name, | |
| typ | |||
| ) |
Declares a new named sarray type for passing between functions
| name | The name for the array type (will create sa_name) |
| typ | The element type stored in the array |
| #define saElemSize | ( | ref | ) | ((ref)._is_sarray ? stGetSize(_saHdr(SAREF(ref))->elemtype) : 0) |
Returns the size in bytes of each array element
| ref | The array (passed by value) |
| #define saElemType | ( | ref | ) | ((ref)._is_sarray ? _saHdr(SAREF(ref))->elemtype : 0) |
Returns the runtime type descriptor for array elements
| ref | The array (passed by value) |
| #define saInitNone { .a = 0 } |
| #define saSize | ( | ref | ) | ((ref)._is_sarray ? _saHdr(SAREF(ref))->count : 0) |
Returns the number of elements in the array
| ref | The array (passed by value) |
| #define saValid | ( | ref | ) | ((ref).a) |
Checks if the array is initialized (non-NULL)
| ref | The array (passed by value) |
Operation flags for sarray functions.
| Enumerator | |
|---|---|
| SA_Unique | Don't insert/merge duplicates |
| SA_Fast | Fast removal by swapping with last element (disrupts order, not valid for sorted arrays)
|
| SA_Inexact | Return insertion point for not found in sorted arrays
|