// License: Modified MIT (NON-AI) // See the LICENSE file in the root directory for license information. // Copyright 2025 Timothy Prepscius #pragma once #include "Debug.h" #include #include "../containers/Map.h" #include "../string/String.h" #include "../threads/Lock.hpp" #include "../algorithm/ExecuteOnDestruct.hpp" #include "../rtti/RTTI.hpp" namespace tjp::core::debug { struct Allocations { struct Allocation { int count = 0; } ; Mutex mutex; Map allocations; void onAllocation (const type_index &t); void onDeallocation (const type_index &t); String log (); static Allocations *shared(); } ; } // namespace #if defined(_DEBUG) #define ALLOC_RECORD(x) \ tjp::core::debug::Allocations::shared()->onAllocation(type_id(*x)) #define DEALLOC_RECORD(x) \ tjp::core::debug::Allocations::shared()->onDeallocation(type_id(*x)) #define SCOPE_RECORD(x) \ struct __ALLOC__##x __alloc__ {}; \ ALLOC_RECORD(&__alloc_); \ tjp::core::ExecuteOnDestruct __dealloc__([&]() { DEALLOC_RECORD(&__alloc__)); \ #define ALLOC_LOG() \ sLogRelease("alloc", tjp::core::debug::Allocations::shared()->log()) #else #define ALLOC_RECORD(x) #define DEALLOC_RECORD(x) #define SCOPE_RECORD(x) #define ALLOC_LOG() #endif