AuroraRuntime/Include/Aurora/Debug/MemoryCrunch.hpp

50 lines
1.5 KiB
C++
Raw Normal View History

/***
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: MemoryCrunch.hpp
2023-08-10 02:42:58 +00:00
Date: 2021-6-9 - 2023-08-10
Author: Reece
***/
#pragma once
namespace Aurora::Debug
{
AUKN_SYM void AddMemoryCrunch();
AUKN_SYM void DecMemoryCrunch();
struct MemoryCrunch
{
inline MemoryCrunch()
{
AddMemoryCrunch();
}
inline ~MemoryCrunch()
{
DecMemoryCrunch();
}
};
2023-10-21 07:19:27 +00:00
struct MemoryCrunchCallOut
{
inline MemoryCrunchCallOut()
{
DecMemoryCrunch();
}
inline ~MemoryCrunchCallOut()
{
AddMemoryCrunch();
}
};
2024-02-28 16:20:07 +00:00
// Memory crunches are used to inform the main allocation functions that failing is a critical mistake.
// Instead of outright failing pursuant to the RuntimeConfig information, we should first try to access the
// emergency memory heap allocated during init. These are useful for trivial functions you wouldn't want
// blowing up under exceptionless paths. In addition, this heap as utilized by ::AddMemoryCrunch is used
// by the debug system to ensure exception handlers, logging, telemetry, and exit conditions do not fail early.
// This way we can still use standard containers of no particular allocator in order to continue without grief.
#define AU_DEBUG_MEMCRUNCH Aurora::Debug::MemoryCrunch AU_CONCAT(__crunch, __COUNTER__);
2024-02-28 16:20:07 +00:00
2023-10-21 07:19:27 +00:00
#define AU_DEBUG_REVERSE_MEMCRUNCH Aurora::Debug::MemoryCrunchCallOut AU_CONCAT(__crunch, __COUNTER__);
}