1 #include <kiba/containers/array.h>
2 #include <kiba/core/id.h>
7 array_of(identifier) returned;
14 KB_ERROR(
"could not allocate new id generator");
17 new_generator->max = 0;
18 new_generator->alloc = alloc;
19 new_generator->returned = array_create(identifier, 64, alloc);
20 if (!new_generator->returned) {
21 KB_ERROR(
"could not allocate storage for returned ids");
22 id_generator_destroy(new_generator);
25 *generator = new_generator;
30 if (generator->returned) {
31 array_destroy(&generator->returned);
37 if (array_size(generator->returned) > 0) {
38 return array_pop(generator->returned);
40 return generator->max++;
45 if (!array_push_checked(&generator->returned, &
id)) {
46 KB_WARN(
"could not return id {usize} to generator {pointer}, id will not be reused",
id, generator);
void * allocator_allocate_aligned(allocator *alloc, usize size, usize alignment)
Allocate aligned memory.
void allocator_free(allocator *alloc, void *mem)
Give back memory to the allocator.
Lightweight layer between platform and other engine components to enable tracing/monitoring.
#define KB_WARN(...)
Log entry with warn log level.
#define KB_ERROR(...)
Log entry with error log level.
Central allocator structure.