CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
Core Types & Information

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...
 

Detailed Description

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:

sa_int32 arr;
saInit(&arr, int32, 16);
arr.a[0] = 42; // Direct access - arr.a is int32*
int32 val = arr.a[5]; // Type-safe element access
#define saInit(out, type, capacity,...)
Definition sarray.h:318

This design enables compile-time type checking while maintaining the flexibility of generic operations through the runtime type system.

Macro Definition Documentation

◆ SA_Grow

#define SA_Grow (   rate)    (((uint32)SA_GROW_##rate) << 24)

SA_Grow(rate)

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.

Parameters
rateGrowth rate (e.g., Auto, Normal, Aggressive, 100, 50, Minimal)
Returns
Formatted flags value for use with saInit() Example:
// Use automatic growth selection
saInit(&arr, int32, 16, SA_Grow(Auto));
// Or specify a fixed rate
saInit(&arr, string, 0, SA_Sorted | SA_Grow(100));
#define SA_Grow(rate)
Definition sarray.h:230
@ SA_Sorted
Maintain sorted order with O(log n) search and O(n) insert.
Definition sarray.h:147

Definition at line 230 of file sarray.h.

◆ saCapacity

#define saCapacity (   ref)    ((ref)._is_sarray ? _saHdr(SAREF(ref))->capacity : 0)

saCapacity(ref)

Returns the allocated capacity of the array

Parameters
refThe array (passed by value)
Returns
Allocated capacity, or 0 if array is NULL

Definition at line 259 of file sarray.h.

◆ saDeclare

#define saDeclare (   name)    saDeclareType(name, name)

saDeclare(name)

Declares a named sarray type where the element type matches the name

Parameters
nameThe type name (both for array and element)

Definition at line 91 of file sarray.h.

◆ saDeclarePtr

#define saDeclarePtr (   name)    saDeclareType(name, name*)

saDeclarePtr(name)

Declares a named sarray type for pointer-to-name elements

Parameters
nameThe base type name (creates array of name*)

Definition at line 98 of file sarray.h.

◆ saDeclareType

#define saDeclareType (   name,
  typ 
)
Value:
typedef union sa_##name { \
_nv_sarray* _debug; \
void* _is_sarray; \
void* _is_sarray_##name; \
typ* a; \
} sa_##name

saDeclareType(name, typ)

Declares a new named sarray type for passing between functions

Parameters
nameThe name for the array type (will create sa_name)
typThe element type stored in the array

Definition at line 78 of file sarray.h.

◆ saElemSize

#define saElemSize (   ref)    ((ref)._is_sarray ? stGetSize(_saHdr(SAREF(ref))->elemtype) : 0)

saElemSize(ref)

Returns the size in bytes of each array element

Parameters
refThe array (passed by value)
Returns
Element size in bytes, or 0 if array is NULL

Definition at line 267 of file sarray.h.

◆ saElemType

#define saElemType (   ref)    ((ref)._is_sarray ? _saHdr(SAREF(ref))->elemtype : 0)

saElemType(ref)

Returns the runtime type descriptor for array elements

Parameters
refThe array (passed by value)
Returns
stype descriptor, or 0 if array is NULL

Definition at line 275 of file sarray.h.

◆ saInitNone

#define saInitNone   { .a = 0 }

saInitNone

Static initializer for an empty/uninitialized array

Definition at line 103 of file sarray.h.

◆ saSize

#define saSize (   ref)    ((ref)._is_sarray ? _saHdr(SAREF(ref))->count : 0)

saSize(ref)

Returns the number of elements in the array

Parameters
refThe array (passed by value)
Returns
Number of elements, or 0 if array is NULL

Definition at line 251 of file sarray.h.

◆ saValid

#define saValid (   ref)    ((ref).a)

saValid(ref)

Checks if the array is initialized (non-NULL)

Parameters
refThe array (passed by value)
Returns
true if array is initialized, false otherwise

Definition at line 283 of file sarray.h.

Enumeration Type Documentation

◆ SARRAY_CREATE_FLAGS_ENUM

Creation flags for sarray initialization.

Enumerator
SA_Ref 

Array references data without copying/destroying (pointer types only)

SA_Sorted 

Maintain sorted order with O(log n) search and O(n) insert.

SA_AutoShrink 

Automatically release memory when array shrinks.

Definition at line 145 of file sarray.h.

◆ SARRAY_FUNC_FLAGS_ENUM

Operation flags for sarray functions.

Enumerator
SA_Unique 

Don't insert/merge duplicates

Note
Valid for saPush(), saMerge()
SA_Fast 

Fast removal by swapping with last element (disrupts order, not valid for sorted arrays)

Note
Valid for saExtract(), saRemove(), saFindRemove()
SA_Inexact 

Return insertion point for not found in sorted arrays

Note
Valid for saFind()

Definition at line 171 of file sarray.h.