Kohi Game Engine
kmemory.h
Go to the documentation of this file.
1 
16 #pragma once
17 
18 #include "defines.h"
19 
21 typedef enum memory_tag {
22  // For temporary use. Should be assigned one of the below or have a new tag created.
43  // "External" vulkan allocations, for reporting purposes only.
47  // Representation of GPU-local/vram
54 
57 
63 
69 
73 void memory_system_shutdown(void* state);
74 
82 KAPI void* kallocate(u64 size, memory_tag tag);
83 
93 KAPI void* kallocate_aligned(u64 size, u16 alignment, memory_tag tag);
94 
104 
111 KAPI void kfree(void* block, u64 size, memory_tag tag);
112 
119 KAPI void kfree_aligned(void* block, u64 size, u16 alignment, memory_tag tag);
120 
129 KAPI void kfree_report(u64 size, memory_tag tag);
130 
140 KAPI b8 kmemory_get_size_alignment(void* block, u64* out_size, u16* out_alignment);
141 
148 KAPI void* kzero_memory(void* block, u64 size);
149 
157 KAPI void* kcopy_memory(void* dest, const void* source, u64 size);
158 
166 KAPI void* kset_memory(void* dest, i32 value, u64 size);
167 
175 
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
signed int i32
Signed 32-bit integer.
Definition: defines.h:39
unsigned short u16
Unsigned 16-bit integer.
Definition: defines.h:22
unsigned long long u64
Unsigned 64-bit integer.
Definition: defines.h:28
KAPI void kfree_report(u64 size, memory_tag tag)
Reports a free associated with the application, but made externally. This can be done for items alloc...
KAPI void * kallocate_aligned(u64 size, u16 alignment, memory_tag tag)
Performs an aligned memory allocation from the host of the given size and alignment....
KAPI void * kcopy_memory(void *dest, const void *source, u64 size)
Performs a copy of the memory at source to dest of the given size.
b8 memory_system_initialize(memory_system_configuration config)
Initializes the memory system.
memory_tag
Tags to indicate the usage of memory allocations made in this system.
Definition: kmemory.h:21
@ MEMORY_TAG_ARRAY
Definition: kmemory.h:24
@ MEMORY_TAG_DIRECT3D
Definition: kmemory.h:45
@ MEMORY_TAG_OPENGL
Definition: kmemory.h:46
@ MEMORY_TAG_HASHTABLE
Definition: kmemory.h:52
@ MEMORY_TAG_DICT
Definition: kmemory.h:27
@ MEMORY_TAG_VULKAN_EXT
Definition: kmemory.h:44
@ MEMORY_TAG_BITMAP_FONT
Definition: kmemory.h:49
@ MEMORY_TAG_SCENE
Definition: kmemory.h:40
@ MEMORY_TAG_GPU_LOCAL
Definition: kmemory.h:48
@ MEMORY_TAG_RING_QUEUE
Definition: kmemory.h:28
@ MEMORY_TAG_BST
Definition: kmemory.h:29
@ MEMORY_TAG_MATERIAL_INSTANCE
Definition: kmemory.h:34
@ MEMORY_TAG_DARRAY
Definition: kmemory.h:26
@ MEMORY_TAG_RENDERER
Definition: kmemory.h:35
@ MEMORY_TAG_KEYMAP
Definition: kmemory.h:51
@ MEMORY_TAG_UNKNOWN
Definition: kmemory.h:23
@ MEMORY_TAG_VULKAN
Definition: kmemory.h:42
@ MEMORY_TAG_AUDIO
Definition: kmemory.h:53
@ MEMORY_TAG_JOB
Definition: kmemory.h:32
@ MEMORY_TAG_STRING
Definition: kmemory.h:30
@ MEMORY_TAG_ENGINE
Definition: kmemory.h:31
@ MEMORY_TAG_LINEAR_ALLOCATOR
Definition: kmemory.h:25
@ MEMORY_TAG_RESOURCE
Definition: kmemory.h:41
@ MEMORY_TAG_ENTITY_NODE
Definition: kmemory.h:39
@ MEMORY_TAG_SYSTEM_FONT
Definition: kmemory.h:50
@ MEMORY_TAG_TRANSFORM
Definition: kmemory.h:37
@ MEMORY_TAG_MAX_TAGS
Definition: kmemory.h:55
@ MEMORY_TAG_ENTITY
Definition: kmemory.h:38
@ MEMORY_TAG_GAME
Definition: kmemory.h:36
@ MEMORY_TAG_TEXTURE
Definition: kmemory.h:33
KAPI void kfree_aligned(void *block, u64 size, u16 alignment, memory_tag tag)
Frees the given block, and untracks its size from the given tag.
KAPI void * kset_memory(void *dest, i32 value, u64 size)
Sets the bytes of memory located at dest to value over the given size.
struct memory_system_configuration memory_system_configuration
The configuration for the memory system.
KAPI u64 get_memory_alloc_count(void)
Obtains the number of times kallocate was called since the memory system was initialized.
void memory_system_shutdown(void *state)
Shuts down the memory system.
KAPI void kfree(void *block, u64 size, memory_tag tag)
Frees the given block, and untracks its size from the given tag.
KAPI b8 kmemory_get_size_alignment(void *block, u64 *out_size, u16 *out_alignment)
Returns the size and alignment of the given block of memory. NOTE: A failure result from this method ...
KAPI void * kzero_memory(void *block, u64 size)
Zeroes out the provided memory block.
KAPI void * kallocate(u64 size, memory_tag tag)
Performs a memory allocation from the host of the given size. The allocation is tracked for the provi...
KAPI void kallocate_report(u64 size, memory_tag tag)
Reports an allocation associated with the application, but made externally. This can be done for item...
KAPI char * get_memory_usage_str(void)
Obtains a string containing a "printout" of memory usage, categorized by memory tag....
The configuration for the memory system.
Definition: kmemory.h:59
u64 total_alloc_size
The total memory size in byes used by the internal allocator for this system.
Definition: kmemory.h:61