mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-24 08:00:14 +00:00
Add macOS and Windows ARM64 builds; fix memory_monitor for macOS
Add macOS matrix job (arm64/macos-15, x86-64/macos-13) using Homebrew. Add Windows ARM64 job using windows-11-arm runner with MSYS2 CLANGARM64. Fix memory_monitor.cpp: add __APPLE__ branch using sysctl hw.memsize/hw.usermem instead of Linux-only sysinfo/proc.
This commit is contained in:
parent
85e28ccec9
commit
880960dcc1
2 changed files with 107 additions and 2 deletions
|
|
@ -5,6 +5,9 @@
|
|||
#include <sstream>
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#elif defined(__APPLE__)
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
#else
|
||||
#include <sys/sysinfo.h>
|
||||
#endif
|
||||
|
|
@ -12,7 +15,7 @@
|
|||
namespace wowee {
|
||||
namespace core {
|
||||
|
||||
#ifndef _WIN32
|
||||
#if !defined(_WIN32) && !defined(__APPLE__)
|
||||
namespace {
|
||||
size_t readMemAvailableBytesFromProc() {
|
||||
std::ifstream meminfo("/proc/meminfo");
|
||||
|
|
@ -31,7 +34,7 @@ size_t readMemAvailableBytesFromProc() {
|
|||
return 0;
|
||||
}
|
||||
} // namespace
|
||||
#endif
|
||||
#endif // !_WIN32 && !__APPLE__
|
||||
|
||||
MemoryMonitor& MemoryMonitor::getInstance() {
|
||||
static MemoryMonitor instance;
|
||||
|
|
@ -48,6 +51,16 @@ void MemoryMonitor::initialize() {
|
|||
totalRAM_ = 16ull * 1024 * 1024 * 1024;
|
||||
LOG_WARNING("Could not detect system RAM, assuming 16GB");
|
||||
}
|
||||
#elif defined(__APPLE__)
|
||||
int64_t physmem = 0;
|
||||
size_t len = sizeof(physmem);
|
||||
if (sysctlbyname("hw.memsize", &physmem, &len, nullptr, 0) == 0) {
|
||||
totalRAM_ = static_cast<size_t>(physmem);
|
||||
LOG_INFO("System RAM detected: ", totalRAM_ / (1024 * 1024 * 1024), " GB");
|
||||
} else {
|
||||
totalRAM_ = 16ull * 1024 * 1024 * 1024;
|
||||
LOG_WARNING("Could not detect system RAM, assuming 16GB");
|
||||
}
|
||||
#else
|
||||
struct sysinfo info;
|
||||
if (sysinfo(&info) == 0) {
|
||||
|
|
@ -69,6 +82,13 @@ size_t MemoryMonitor::getAvailableRAM() const {
|
|||
return static_cast<size_t>(status.ullAvailPhys);
|
||||
}
|
||||
return totalRAM_ / 2;
|
||||
#elif defined(__APPLE__)
|
||||
int64_t usermem = 0;
|
||||
size_t len = sizeof(usermem);
|
||||
if (sysctlbyname("hw.usermem", &usermem, &len, nullptr, 0) == 0) {
|
||||
return static_cast<size_t>(usermem);
|
||||
}
|
||||
return totalRAM_ / 2;
|
||||
#else
|
||||
// Best source on Linux for reclaimable memory headroom.
|
||||
if (size_t memAvailable = readMemAvailableBytesFromProc(); memAvailable > 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue