32static bool array_realloc(
array_t* self,
size_t capacity_to_alloc)
34 void* new_storage = reallocarray(self->
start, capacity_to_alloc, self->
type_size);
35 if (new_storage == NULL)
37 self->
start = new_storage;
49 const size_t wanted = self->
count + count;
52 if (wanted <= self->capacity)
56 while (required < wanted)
58 return array_realloc(self, required);
67 return array_realloc(self, self->
count);
Internal state of a dynamic array.
#define ARRAY_INITIAL_SIZE
Number of elements allocated at minimum.
#define ARRAY_GROWTH_FACTOR
Factor used to multiply the capacity with.
bool array_trim(array_t *self)
Resizes the underlying storage to fit exactly the current elements count.
size_t array_offset(const array_t *self, size_t count)
The size in memory of count elements.
bool array_reserve(array_t *self, size_t count)
Ensures the array has enough capacity to fit count new elements, reallocating if needed.
O2S array implementation.
void * start
Underlying storage.
size_t type_size
Size in bytes of a single element.
size_t count
Number of elements currently stored.
size_t capacity
Number of elements that can fit in the storage.