Kohi Game Engine
dynamic_allocator.h
Go to the documentation of this file.
1 
12 #pragma once
13 
14 #include "defines.h"
15 
17 typedef struct dynamic_allocator {
19  void* memory;
21 
32 KAPI b8 dynamic_allocator_create(u64 total_size, u64* memory_requirement, void* memory, dynamic_allocator* out_allocator);
33 
41 
50 
60 
69 KAPI b8 dynamic_allocator_free(dynamic_allocator* allocator, void* block, u64 size);
70 
80 
90 KAPI b8 dynamic_allocator_get_size_alignment(void* block, u64* out_size, u16* out_alignment);
91 
99 
107 
This file contains global type definitions which are used throughout the entire engine and applicatio...
#define KAPI
Import/export qualifier.
Definition: defines.h:177
_Bool b8
8-bit boolean type
Definition: defines.h:58
unsigned short u16
Unsigned 16-bit integer.
Definition: defines.h:22
unsigned long long u64
Unsigned 64-bit integer.
Definition: defines.h:28
KAPI b8 dynamic_allocator_free(dynamic_allocator *allocator, void *block, u64 size)
Frees the given block of memory.
struct dynamic_allocator dynamic_allocator
The dynamic allocator structure.
KAPI void * dynamic_allocator_allocate(dynamic_allocator *allocator, u64 size)
Allocates the given amount of memory from the provided allocator.
KAPI void * dynamic_allocator_allocate_aligned(dynamic_allocator *allocator, u64 size, u16 alignment)
Allocates the given amount of aligned memory from the provided allocator.
KAPI b8 dynamic_allocator_destroy(dynamic_allocator *allocator)
Destroys the given allocator.
KAPI b8 dynamic_allocator_free_aligned(dynamic_allocator *allocator, void *block)
Frees the given block of aligned memory. Technically the same as calling dynamic_allocator_free,...
KAPI b8 dynamic_allocator_create(u64 total_size, u64 *memory_requirement, void *memory, dynamic_allocator *out_allocator)
Creates a new dynamic allocator. Should be called twice; once to obtain the memory amount required (p...
KAPI u64 dynamic_allocator_header_size(void)
KAPI b8 dynamic_allocator_get_size_alignment(void *block, u64 *out_size, u16 *out_alignment)
Obtains the size and alignment of the given block of memory. Can fail if invalid data is passed.
KAPI u64 dynamic_allocator_free_space(dynamic_allocator *allocator)
Obtains the amount of free space left in the provided allocator.
KAPI u64 dynamic_allocator_total_space(dynamic_allocator *allocator)
Obtains the amount of total space originally available in the provided allocator.
The dynamic allocator structure.
Definition: dynamic_allocator.h:17
void * memory
The allocated memory block for this allocator to use.
Definition: dynamic_allocator.h:19