Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

fix: correct RAM usage #2019

Merged
merged 2 commits into from
Feb 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions engine/utils/hardware/ram_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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())};
Expand Down
Loading