flatten 20260225

This commit is contained in:
Timothy Prepscius
2026-02-25 12:43:06 -05:00
commit 996151a56a
521 changed files with 46722 additions and 0 deletions

58
tjp/core/debug/Allocations.h Executable file
View File

@@ -0,0 +1,58 @@
// 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 <typeinfo>
#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<String, Allocation> 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