Skip to content

Commit acfaf8a

Browse files
Calculate virtual_available in iware::system::memory() on Darwin
Closes #81
1 parent 2a56cb1 commit acfaf8a

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/system/memory/memory_darwin.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,21 @@
1919
iware::system::memory_t iware::system::memory() noexcept {
2020
iware::system::memory_t ret{};
2121

22-
const auto host = mach_host_self();
23-
2422
const auto ctl_ram = iware::detail::sysctl(CTL_HW, HW_MEMSIZE);
2523
if(!ctl_ram.empty()) {
2624
const auto ram = iware::detail::deconstruct_sysctl_int(ctl_ram);
2725
if(ram.first)
2826
ret.virtual_total = ram.second;
2927
}
3028

31-
vm_statistics64 stats;
32-
natural_t count = HOST_VM_INFO64_COUNT;
33-
if(host_statistics64(host, HOST_VM_INFO64, reinterpret_cast<host_info64_t>(&stats), &count) == KERN_SUCCESS)
34-
ret.virtual_available = stats.free_count * getpagesize();
35-
3629
ret.physical_total = ret.virtual_total;
3730
ret.physical_available = ret.virtual_available;
3831

32+
std::uint32_t mem_free;
33+
auto mem_free_length = sizeof(mem_free);
34+
if(sysctlbyname("kern.memorystatus_level", &mem_free, &mem_free_length, nullptr, 0) != -1)
35+
ret.virtual_available = mem_free * ret.virtual_total / 100;
36+
3937
return ret;
4038
}
4139

0 commit comments

Comments
 (0)