diff --git a/include/core/basalt_memory.h b/include/core/basalt_memory.h index a30b799..10073ea 100644 --- a/include/core/basalt_memory.h +++ b/include/core/basalt_memory.h @@ -79,7 +79,7 @@ namespace basalt template T* allocT(u64 num_elements, MEMORY_TAG tag) - { return alloc(num_elements*sizeof(T), tag); } + { return (T*)alloc(num_elements*sizeof(T), tag); } template T* setzeroT(T * dst, u64 num_elements) { return setzero(dst, num_elements*sizeof(T)); } diff --git a/src/core/basalt_memory.cpp b/src/core/basalt_memory.cpp index 97a1077..c6703e8 100644 --- a/src/core/basalt_memory.cpp +++ b/src/core/basalt_memory.cpp @@ -1,11 +1,12 @@ -#include "core/basalt_logger.h" -#include "core/basalt_memory.h" - #include #include #include #include +#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;