47 KB_ERROR(
"could not allocate {usize} bytes for the linear_allocator_block",
size);
53 block->
data = block + 1;
54 KB_TRACE(
"created linear_allocator_block with size {usize}",
size);
63 KB_ERROR(
"could not allocate memory for initial linear_allocator_block");
72 KB_TRACE(
"created linear_allocator with initial size {usize}",
size);
82 KB_TRACE(
"destroying linear_allocator_block with size {usize}", prev_block->
size);
83 memory_page_free(prev_block);
85 KB_TRACE(
"destroyed linear_allocator");
94 fitting_block = block;
101 if (fitting_block ==
KB_NULL) {
102 KB_TRACE(
"did not find fitting block, creating new one");
103 usize new_size = prev_block->
size;
104 if (
size > new_size) {
106 "new block size {usize} is not enough for requested allocation of {usize} bytes, using the requested "
107 "size as new block size",
113 if (fitting_block ==
KB_NULL) {
114 KB_ERROR(
"could not allocate memory for linear_allocator_block");
117 alloc->
state = fitting_block;
119 void *ret = (u8 *) fitting_block->
data + fitting_block->
cur_offset;
128 KB_INFO(
"linear_allocator is not able to free individual allocations");
void allocator_implementation(allocator *alloc, allocator_impl_destroy_fn destroy, allocator_impl_allocate_fn allocate, allocator_impl_free_fn free, allocator_impl_free_all_fn free_all)
Set allocator implementation.
Lightweight layer between platform and other engine components to enable tracing/monitoring.
#define UNUSED(x)
Mark parameter as unused.
#define KB_NULL
Value of an invalid ptr (nullptr).
void linear_allocator_free(allocator *alloc, void *mem, usize size)
void linear_allocator_destroy(allocator *alloc)
void * linear_allocator_allocate(allocator *alloc, usize size)
b8 linear_allocator_create(allocator *alloc, usize size)
void linear_allocator_free_all(allocator *alloc)
struct linear_allocator_block linear_allocator_block
Internal state of the linear_allocator.
linear_allocator_block * linear_allocator_block_create(usize size, linear_allocator_block *next)
Create a new linear_allocator_block.
Function signatures for linear allocator implementation.
#define KB_DEBUG(...)
Log entry with debug log level.
#define KB_ERROR(...)
Log entry with error log level.
#define KB_TRACE(...)
Log entry with trace log level.
#define KB_INFO(...)
Log entry with info log level.
Central allocator structure.
void * state
Type specific state of the allocator.
Internal state of the linear_allocator.
usize cur_offset
Current offset into the block for the next allocation.
struct linear_allocator_block * next
Pointer to the next block in the linked list.
usize size
Size of the managable space.
void * data
Pointer to beginning of managed memory block.