The bj_array type is a sequence container that encapsulates dynamic C-style arrays.
More...
The elements are stored contiguously, allowing access using offsets.
The storage of the array is expanded as needed.
|
typedef struct bj_array_t | bj_array |
| Typedef for the bj_array_t struct.
|
|
◆ bj_array_new_t
#define bj_array_new_t |
( |
| T | ) |
|
Value:
bj_array * bj_array_new(size_t bytes_payload)
Creates a new bj_array with a payload size specified in bytes.
- Parameters
-
- Returns
- A pointer to the newly created bj_array object.
- See also
- bj_array_new
- Examples
- array.c.
◆ bj_array_alloc()
◆ bj_array_at()
void * bj_array_at |
( |
const bj_array * | array, |
|
|
size_t | at ) |
- Parameters
-
array | The array object to retrieve the value from. |
at | Index of the element to retrieve. |
- Returns
- Pointer to the value at the specified index.
- Return values
-
- Examples
- array.c.
◆ bj_array_capacity()
size_t bj_array_capacity |
( |
const bj_array * | array | ) |
|
- Parameters
-
array | The array object to get the capacity from. |
- Returns
- Current capacity of the array.
- Return values
-
- Examples
- array.c.
◆ bj_array_clear()
- Parameters
-
array | The array object to clear. |
If the array is already empty, this function does nothing. To release the internal memory, call bj_array_shrink after clearing.
- Note
- When called on a null object, this function does nothing.
- Examples
- array.c.
◆ bj_array_data()
void * bj_array_data |
( |
const bj_array * | array | ) |
|
- Parameters
-
array | The array object to get the data pointer from. |
- Returns
- Pointer to the underlying data.
- Return values
-
- Examples
- array.c.
◆ bj_array_del()
- Parameters
-
p_array | Pointer to the bj_array object to delete. |
- Examples
- array.c.
◆ bj_array_init()
- Parameters
-
p_instance | A pointer to an array object. |
bytes_payload | Size of each element in bytes. |
- Returns
- A pointer to the newly created bj_array object.
◆ bj_array_len()
size_t bj_array_len |
( |
const bj_array * | array | ) |
|
- Parameters
-
array | The array object to get the length from. |
- Returns
- Number of elements in the array.
- Return values
-
- Examples
- array.c.
◆ bj_array_new()
bj_array * bj_array_new |
( |
size_t | bytes_payload | ) |
|
◆ bj_array_pop()
- Parameters
-
array | The array object to remove the last value from. |
This function reduces the array size by one.
- Note
- When called on a null object, this function does nothing.
- Examples
- array.c.
◆ bj_array_push()
void bj_array_push |
( |
bj_array * | array, |
|
|
const void * | value ) |
- Parameters
-
array | The array object to push the value into. |
value | Pointer to the value to append. |
Copies the memory pointed to by value
into the array using bj_memcpy.
- Note
- Calling this function may reserve more space in the array, which invalidates the data pointer.
-
When called on a null object, this function does nothing.
- Examples
- array.c.
◆ bj_array_reserve()
void bj_array_reserve |
( |
bj_array * | array, |
|
|
size_t | capacity ) |
- Parameters
-
array | The array object to reserve memory for. |
capacity | Number of elements to reserve space for. |
If capacity
is smaller than the current capacity, this function does nothing. Otherwise, it reallocates memory to fit the new capacity.
- Note
- When called on a null object, this function does nothing. This function invalidates the array data pointer if reallocation is performed.
◆ bj_array_reset()
void bj_array_reset |
( |
bj_array * | p_array | ) |
|
- Parameters
-
p_array | The array object to reset. |
◆ bj_array_set_len()
void bj_array_set_len |
( |
bj_array * | array, |
|
|
size_t | len ) |
- Parameters
-
array | The array object to resize. |
len | New length of the array. |
If len == 0
, this function is equivalent to calling bj_array_clear.
- Note
- When called on a null object, this function does nothing. This function invalidates the array data pointer if reallocation is necessary.
◆ bj_array_shrink()
void bj_array_shrink |
( |
bj_array * | array | ) |
|
- Parameters
-
array | The array object to shrink. |
This function reallocates the memory used by the array to fit its current length.
- Note
- When called on a null object, this function does nothing. This function invalidates the array data pointer.
- Examples
- array.c.