Kelsidavis-WoWee/include/core/memory_monitor.hpp
Pavel Okhlopkov 312994be83 world loading memory pressure detector
Signed-off-by: Pavel Okhlopkov <pavel.okhlopkov@flant.com>
2026-04-06 21:05:20 +03:00

54 lines
1.2 KiB
C++

#pragma once
#include <cstddef>
#include <cstdint>
namespace wowee {
namespace core {
/**
* Monitors system memory and provides dynamic cache sizing
*/
class MemoryMonitor {
public:
static MemoryMonitor& getInstance();
/**
* Initialize memory monitoring
*/
void initialize();
/**
* Get total system RAM in bytes
*/
size_t getTotalRAM() const { return totalRAM_; }
/**
* Get currently available RAM in bytes
*/
size_t getAvailableRAM() const;
/**
* Get recommended cache budget (80% of available RAM, capped at 90% of total RAM)
*/
size_t getRecommendedCacheBudget() const;
/**
* Check if system is under memory pressure (< 10% RAM available)
*/
bool isMemoryPressure() const;
/**
* Check if system is under severe memory pressure (< 15% RAM available).
* At this level, background loading should pause entirely until memory
* is freed — continuing to allocate risks OOM-killing other applications.
*/
bool isSevereMemoryPressure() const;
private:
MemoryMonitor() = default;
size_t totalRAM_ = 0;
};
} // namespace core
} // namespace wowee