Updated allocT implementation to cast the returned void* to a T*.

Moved builtin memory tag names to top of source file because it didn't like being forward declared. TODO: Revisit this later
Fixed compilation error where the source-local function get_eng_unit did not return the modified value.
Shuffled include order around to fix compilation issues.
This commit is contained in:
2025-06-23 00:44:49 +10:00
parent 87f66e291b
commit e4eb380ff1
2 changed files with 32 additions and 32 deletions

View File

@@ -1,11 +1,12 @@
#include "core/basalt_logger.h"
#include "core/basalt_memory.h"
#include <immintrin.h>
#include <memory.h>
#include <string.h>
#include <cmath>
#include "core/basalt_memory.h"
#include "core/basalt_logger.h"
#include "basalt_defines.h"
static struct {
i64 alloc_total;
@@ -13,8 +14,31 @@ static struct {
i64 zone_alloc[MEMORY_TAG_ZONE_MAX + 1];
} basalt_memory_state;
static const char* basalt_memory_class_names[MEMORY_TAG_CLASS_MAX_BUILTIN];
static const char* basalt_memory_zone_names[MEMORY_TAG_ZONE_MAX_BUILTIN];
static const char* basalt_memory_class_names[MEMORY_TAG_CLASS_MAX_BUILTIN] = {
"UNKNOWN",
"ARRAY",
"DYNARRAY",
"STRING",
"CIRCULAR_BUFFER",
"DICT",
"BINTREE",
"OCTTREE",
"TEXTURE",
"JOB",
"TRANSFORM",
"RENDER_OBJECT",
"MATERIAL"
};
static const char* basalt_memory_zone_names[MEMORY_TAG_ZONE_MAX_BUILTIN] = {
"UNKNOWN",
"SCENE",
"APPLICATION",
"RENDERER",
"ENGINE",
"EVENT",
"DEBUG",
"AUDIO"
};
static u8 basalt_memory_class_name_lengths[MEMORY_TAG_CLASS_MAX_BUILTIN];
static u8 basalt_memory_zone_name_lengths[MEMORY_TAG_ZONE_MAX_BUILTIN];
@@ -41,6 +65,7 @@ void* basalt::mem::alloc(u64 num_bytes, MEMORY_TAG tag)
ptr = _mm_malloc(num_bytes, alignment);
else if ((tag & MEMORY_TAG_MASK_ALIGN) == MEMORY_TAG_ALIGN_PAGE)
ptr = _mm_malloc(num_bytes, alignment);
if (ptr != nullptr)
{
basalt_memory_state.alloc_total += num_bytes;
@@ -111,6 +136,7 @@ f64 get_eng_unit(f64 x, char* unit)
x *= 1000.0;
}
*unit = units[order + order_index_offset];
return x;
}
char* basalt::mem::get_memory_usage_string(void)
@@ -160,32 +186,6 @@ char* basalt::mem::get_memory_usage_string(void)
return ret;
}
static const char* basalt_memory_class_names[MEMORY_TAG_CLASS_MAX_BUILTIN] = {
"UNKNOWN",
"ARRAY",
"DYNARRAY",
"STRING",
"CIRCULAR_BUFFER",
"DICT",
"BINTREE",
"OCTTREE",
"TEXTURE",
"JOB",
"TRANSFORM",
"RENDER_OBJECT",
"MATERIAL"
};
static const char* basalt_memory_zone_names[MEMORY_TAG_ZONE_MAX_BUILTIN] = {
"UNKNOWN",
"SCENE",
"APPLICATION",
"RENDERER",
"ENGINE",
"EVENT",
"DEBUG",
"AUDIO"
};
i64 basalt::mem::get_memory_tag_class_name(MEMORY_TAG memory_class, char* out_buf, u64 out_buf_size)
{
constexpr u16 user_index_max = MEMORY_TAG_CLASS_MAX - MEMORY_TAG_CLASS_MAX_BUILTIN + 1;