dynamic_array.h v0.3.1
Reference-counted dynamic arrays for C
Loading...
Searching...
No Matches
Functions
Array Access

Functions for reading and writing array elements. More...

Functions

DA_DEF void * da_get (da_array arr, int index)
 Gets a pointer to an element at the specified index.
 
DA_DEF void * da_data (da_array arr)
 Gets direct pointer to the underlying data array.
 
DA_DEF void da_set (da_array arr, int index, const void *element)
 Sets the value of an element at the specified index.
 

Detailed Description

Functions for reading and writing array elements.

Function Documentation

◆ da_data()

DA_DEF void * da_data ( da_array  arr)

Gets direct pointer to the underlying data array.

Parameters
arrArray to access (must not be NULL)
Returns
Pointer to raw data array (like stb_ds.h style)
Note
Enables direct indexing: ((int*)da_data(arr))[i]
Pointer is valid until array is modified or released
No bounds checking - use with care
int* data = (int*)da_data(arr);
data[0] = 42; // Direct array-style access
data[1] = 99;
DA_DEF void * da_data(da_array arr)
Gets direct pointer to the underlying data array.
Definition dynamic_array.h:1562

◆ da_get()

DA_DEF void * da_get ( da_array  arr,
int  index 
)

Gets a pointer to an element at the specified index.

Parameters
arrArray to access (must not be NULL)
indexElement index (must be >= 0 and < length)
Returns
Pointer to element at index
Note
Asserts on out-of-bounds access
Returned pointer is valid until array is modified or released
int* ptr = (int*)da_get(arr, 0);
*ptr = 42; // Direct modification
DA_DEF void * da_get(da_array arr, int index)
Gets a pointer to an element at the specified index.
Definition dynamic_array.h:1556

◆ da_set()

DA_DEF void da_set ( da_array  arr,
int  index,
const void *  element 
)

Sets the value of an element at the specified index.

Parameters
arrArray to modify (must not be NULL)
indexElement index (must be >= 0 and < length)
elementPointer to element data to copy (must not be NULL)
Note
Asserts on out-of-bounds access or NULL parameters
Copies element_size bytes from element pointer
int value = 42;
da_set(arr, 0, &value);
DA_DEF void da_set(da_array arr, int index, const void *element)
Sets the value of an element at the specified index.
Definition dynamic_array.h:1567