From deed9a589f96970e12707f3ee8c8ae7299653a95 Mon Sep 17 00:00:00 2001 From: sangjanai Date: Mon, 24 Feb 2025 13:03:44 +0700 Subject: [PATCH] fix: correct RAM usage --- engine/utils/hardware/ram_info.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/engine/utils/hardware/ram_info.h b/engine/utils/hardware/ram_info.h index 1ee4a55f7..14a48d798 100644 --- a/engine/utils/hardware/ram_info.h +++ b/engine/utils/hardware/ram_info.h @@ -17,12 +17,12 @@ inline Memory GetMemoryInfo() { hwinfo::Memory m; #if defined(__APPLE__) && defined(__MACH__) int64_t total_memory = 0; - int64_t used_memory = 0; + int64_t avail_memory = 0; size_t length = sizeof(total_memory); sysctlbyname("hw.memsize", &total_memory, &length, NULL, 0); - // Get used memory (this is a rough estimate) + // Get avail memory (this is a rough estimate) vm_size_t page_size; mach_msg_type_number_t count = HOST_VM_INFO_COUNT; @@ -31,12 +31,10 @@ inline Memory GetMemoryInfo() { if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vm_stat, &count) == KERN_SUCCESS) { - used_memory = - (vm_stat.active_count + vm_stat.inactive_count + vm_stat.wire_count) * - page_size; + avail_memory = (vm_stat.free_count + vm_stat.inactive_count) * page_size; } return Memory{.total_MiB = ByteToMiB(total_memory), - .available_MiB = ByteToMiB(total_memory - used_memory)}; + .available_MiB = ByteToMiB(avail_memory)}; #elif defined(__linux__) || defined(_WIN32) return Memory{.total_MiB = ByteToMiB(m.total_Bytes()), .available_MiB = ByteToMiB(m.available_Bytes())};