Kohi Game Engine
|
This file contains the structures and functions of the memory system. This is responsible for memory interaction with the platform layer, such as allocations/frees and tagging of memory allocations. More...
#include "defines.h"
Go to the source code of this file.
Data Structures | |
struct | memory_system_configuration |
The configuration for the memory system. More... | |
Typedefs | |
typedef enum memory_tag | memory_tag |
Tags to indicate the usage of memory allocations made in this system. More... | |
typedef struct memory_system_configuration | memory_system_configuration |
The configuration for the memory system. More... | |
Enumerations | |
enum | memory_tag { MEMORY_TAG_UNKNOWN , MEMORY_TAG_ARRAY , MEMORY_TAG_LINEAR_ALLOCATOR , MEMORY_TAG_DARRAY , MEMORY_TAG_DICT , MEMORY_TAG_RING_QUEUE , MEMORY_TAG_BST , MEMORY_TAG_STRING , MEMORY_TAG_ENGINE , MEMORY_TAG_JOB , MEMORY_TAG_TEXTURE , MEMORY_TAG_MATERIAL_INSTANCE , MEMORY_TAG_RENDERER , MEMORY_TAG_GAME , MEMORY_TAG_TRANSFORM , MEMORY_TAG_ENTITY , MEMORY_TAG_ENTITY_NODE , MEMORY_TAG_SCENE , MEMORY_TAG_RESOURCE , MEMORY_TAG_VULKAN , MEMORY_TAG_VULKAN_EXT , MEMORY_TAG_DIRECT3D , MEMORY_TAG_OPENGL , MEMORY_TAG_GPU_LOCAL , MEMORY_TAG_BITMAP_FONT , MEMORY_TAG_SYSTEM_FONT , MEMORY_TAG_KEYMAP , MEMORY_TAG_HASHTABLE , MEMORY_TAG_AUDIO , MEMORY_TAG_MAX_TAGS } |
Tags to indicate the usage of memory allocations made in this system. More... | |
Functions | |
b8 | memory_system_initialize (memory_system_configuration config) |
Initializes the memory system. More... | |
void | memory_system_shutdown (void *state) |
Shuts down the memory system. More... | |
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 provided tag. More... | |
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. The allocation is tracked for the provided tag. NOTE: Memory allocated this way must be freed using kfree_aligned. More... | |
KAPI void | kallocate_report (u64 size, memory_tag tag) |
Reports an allocation associated with the application, but made externally. This can be done for items allocated within 3rd party libraries, for example, to track allocations but not perform them. More... | |
KAPI void | kfree (void *block, u64 size, memory_tag tag) |
Frees the given block, and untracks its size from the given tag. More... | |
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. More... | |
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 allocated within 3rd party libraries, for example, to track frees but not perform them. More... | |
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 most likely indicates heap corruption. More... | |
KAPI void * | kzero_memory (void *block, u64 size) |
Zeroes out the provided memory block. More... | |
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. More... | |
KAPI void * | kset_memory (void *dest, i32 value, u64 size) |
Sets the bytes of memory located at dest to value over the given size. More... | |
KAPI char * | get_memory_usage_str (void) |
Obtains a string containing a "printout" of memory usage, categorized by memory tag. The memory should be freed by the caller. More... | |
KAPI u64 | get_memory_alloc_count (void) |
Obtains the number of times kallocate was called since the memory system was initialized. More... | |
This file contains the structures and functions of the memory system. This is responsible for memory interaction with the platform layer, such as allocations/frees and tagging of memory allocations.
typedef struct memory_system_configuration memory_system_configuration |
The configuration for the memory system.
typedef enum memory_tag memory_tag |
Tags to indicate the usage of memory allocations made in this system.
enum memory_tag |
Tags to indicate the usage of memory allocations made in this system.
Obtains the number of times kallocate was called since the memory system was initialized.
KAPI char* get_memory_usage_str | ( | void | ) |
Obtains a string containing a "printout" of memory usage, categorized by memory tag. The memory should be freed by the caller.
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 provided tag.
size | The size of the allocation. |
tag | Indicates the use of the allocated block. |
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. The allocation is tracked for the provided tag. NOTE: Memory allocated this way must be freed using kfree_aligned.
size | The size of the allocation. |
alignment | The alignment in bytes. |
tag | Indicates the use of the allocated block. |
KAPI void kallocate_report | ( | u64 | size, |
memory_tag | tag | ||
) |
Reports an allocation associated with the application, but made externally. This can be done for items allocated within 3rd party libraries, for example, to track allocations but not perform them.
size | The size of the allocation. |
tag | Indicates the use of the allocated block. |
Performs a copy of the memory at source to dest of the given size.
dest | A pointer to the destination block of memory to copy to. |
source | A pointer to the source block of memory to copy from. |
size | The amount of memory in bytes to be copied over. |
KAPI void kfree | ( | void * | block, |
u64 | size, | ||
memory_tag | tag | ||
) |
Frees the given block, and untracks its size from the given tag.
block | A pointer to the block of memory to be freed. |
size | The size of the block to be freed. |
tag | The tag indicating the block's use. |
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.
block | A pointer to the block of memory to be freed. |
size | The size of the block to be freed. |
tag | The tag indicating the block's use. |
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 allocated within 3rd party libraries, for example, to track frees but not perform them.
size | The size in bytes. |
tag | The tag indicating the block's use. |
Returns the size and alignment of the given block of memory. NOTE: A failure result from this method most likely indicates heap corruption.
block | The memory block. |
out_size | A pointer to hold the size of the block. |
out_alignment | A pointer to hold the alignment of the block. |
Sets the bytes of memory located at dest to value over the given size.
dest | A pointer to the destination block of memory to be set. |
value | The value to be set. |
size | The size in bytes to copy over to. |
Zeroes out the provided memory block.
block | A pointer to the block of memory to be zeroed out. |
size | The size in bytes to zero out. |
A | pointer to the zeroed out block of memory. |
b8 memory_system_initialize | ( | memory_system_configuration | config | ) |
Initializes the memory system.
config | The configuration for this system. |
void memory_system_shutdown | ( | void * | state | ) |
Shuts down the memory system.