O2S C Library 1.8.2
Provide high-level data-structures and other fundamental tools for C projects
Loading...
Searching...
No Matches
constructors_destructors.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* ____ _ _____ ____ _ _ _ _____ _ _ ____ ____ */
3/* / ___| / \ | ___| _ \ / \ | \ | | |_ _| || | | _ \/ ___| */
4/* \___ \ / _ \ | |_ | |_) | / _ \ | \| | | | | || |_| | | \___ \ */
5/* ___) / ___ \| _| | _ < / ___ \| |\ | | | |__ _| |_| |___) | */
6/* |____/_/ \_|_| |_| \_/_/ \_|_| \_| |_| |_| |____/|____/ */
7/* */
14/* ************************************************************************** */
15
16#include "private.h"
17
18#include "o2s/array.h"
19
20#include <stdlib.h> // free
21
23array_t array_new(size_t type_size)
24{
25 return (array_t){.start = NULL, .type_size = type_size, .count = 0, .capacity = 0};
26}
27
34{
35 if (self->start)
36 free(self->start);
37 self->count = 0;
38 self->capacity = 0;
39 self->start = NULL;
40}
41
47void array_clear_f(array_t* self, void (*cleanup)(void*))
48{
49 array_iter(self, cleanup);
50 array_clear(self);
51}
void array_clear(array_t *self)
Clears properly the array.
array_t array_new(size_t type_size)
Contructs an empty array, no memory is allocated.
void array_clear_f(array_t *self, void(*cleanup)(void *))
Release the resources of each elements before clearing the array.
Internal state of a dynamic array.
Dynamic arrays.
void array_iter(const array_t *self, void(*function)(void *))
Call function on each element.
Definition iter.c:21
O2S array implementation.
Definition array.h:24
void * start
Underlying storage.
Definition array.h:25
size_t count
Number of elements currently stored.
Definition array.h:27
size_t capacity
Number of elements that can fit in the storage.
Definition array.h:28