dtarray_float
Fixed-size float array with packing support
This group of functions provides fixed-size float array management. It supports copying, comparison, and stream packing. The implementation has single-allocation ownership and requires explicit disposal.
Mini-guide
- Create an instance by calling the allocator with a positive element count.
- Access the
itemspointer directly for element storage. - Dispose the instance when done to free memory.
- Serialize by computing pack length before writing to a buffer.
- Deserialize by unpacking into an existing array capacity.
Example
dtarray_float_t* a = NULL;
dtarray_float_t* b = NULL;
if (dtarray_float_create(&a, 4) == NULL &&
dtarray_float_create(&b, 4) == NULL)
{
a->items[0] = 1.0f;
a->items[1] = 2.0f;
dtarray_float_copy(a, b);
bool same = dtarray_float_equals(a, b);
(void)same;
}
dtarray_float_dispose(a);
dtarray_float_dispose(b);
Data structures
dtarray_float_t
Represents a fixed-size array of float elements.
Members:
int32_t countNumber of elements in the array.
float* itemsPointer to the element storage.
Functions
dtarray_float_copy
Copies elements from a source array into a destination array.
Params:
const dtarray_float_t* srcSource array to read from.
dtarray_float_t* destDestination array to write into.
Return: void No return value.
dtarray_float_create
Allocates and initializes a float array with a fixed element count.
Params:
dtarray_float_t** array_floatReceives the allocated array pointer.
int countNumber of elements to allocate.
Return: dterr_t* Error object on failure, or NULL on success.
dtarray_float_dispose
Releases memory owned by a float array.
Params:
dtarray_float_t* selfArray instance to dispose.
Return: void No return value.
dtarray_float_equals
Compares two float arrays for equal size and contents.
Params:
const dtarray_float_t* aFirst array to compare.
const dtarray_float_t* bSecond array to compare.
Return: bool True if arrays are equal.
dtarray_float_pack
Serializes the array into a byte buffer.
Params:
const dtarray_float_t* selfArray to serialize.
uint8_t* outputOutput buffer to write into.
int32_t offsetStarting offset in the buffer.
int32_t lengthTotal length of the buffer.
Return: int32_t Number of bytes written, or negative on error.
dtarray_float_pack_length
Computes the number of bytes required to serialize the array.
Params:
const dtarray_float_t* selfArray to measure.
Return: int32_t Required byte length, or negative on error.
dtarray_float_unpack
Deserializes array contents from a byte buffer.
Params:
dtarray_float_t* selfArray to populate.
const uint8_t* inputInput buffer to read from.
int32_t offsetStarting offset in the buffer.
int32_t lengthTotal length of the buffer.
Return: int32_t Number of bytes consumed, or negative on error.