Kohi Game Engine
|
This file contains the linear allocator implementation. More...
#include "defines.h"
Go to the source code of this file.
Data Structures | |
struct | linear_allocator |
The data structure for a linear allocator. More... | |
Typedefs | |
typedef struct linear_allocator | linear_allocator |
The data structure for a linear allocator. More... | |
Functions | |
KAPI void | linear_allocator_create (u64 total_size, void *memory, linear_allocator *out_allocator) |
Creates a linear allocator of the given size. More... | |
KAPI void | linear_allocator_destroy (linear_allocator *allocator) |
Destroys the given allocator. If the allocator owns its memory, it is freed at this time. More... | |
KAPI void * | linear_allocator_allocate (linear_allocator *allocator, u64 size) |
Allocates the given amount from the allocator. More... | |
KAPI void | linear_allocator_free_all (linear_allocator *allocator, b8 clear) |
Frees everything in the allocator, effectively moving its pointer back to the beginning. Does not free internal memory, if owned. Only resets the pointer. More... | |
This file contains the linear allocator implementation.
A linear allocator allocates memory from its internal block of memory in a linear fashion. That is, one after another, moving a pointer along as it goes. A linear allocator can perform allocations of any size, but allocation sizes are not stored, and thus allocations made in this way are not individually freeable. Only the entire thing can be freed. This comes with the benefit of speed at a cost of flexibility.
typedef struct linear_allocator linear_allocator |
The data structure for a linear allocator.
KAPI void* linear_allocator_allocate | ( | linear_allocator * | allocator, |
u64 | size | ||
) |
Allocates the given amount from the allocator.
allocator | A pointer to the allocator to allocate from. |
size | The size to be allocated. |
KAPI void linear_allocator_create | ( | u64 | total_size, |
void * | memory, | ||
linear_allocator * | out_allocator | ||
) |
Creates a linear allocator of the given size.
total_size | The total amount in bytes the allocator will hold. |
memory | Allocated block of memory matching size above, or 0. If 0, a dynamic allocation is performed and this allocator is considered to own that memory. |
out_allocator | A pointer to hold the new allocator. |
KAPI void linear_allocator_destroy | ( | linear_allocator * | allocator | ) |
Destroys the given allocator. If the allocator owns its memory, it is freed at this time.
allocator | A pointer to the allocator to be destroyed. |
KAPI void linear_allocator_free_all | ( | linear_allocator * | allocator, |
b8 | clear | ||
) |
Frees everything in the allocator, effectively moving its pointer back to the beginning. Does not free internal memory, if owned. Only resets the pointer.
allocator | A pointer to the allocator to free. |
clear | Indicates whether or not to clear/zero the memory. Enabling this obviously takes more processing power. |