21 #include <mach/mach.h>
22 #include <sys/sysctl.h>
23 #include <sys/types.h>
27 int mib[] = {CTL_HW, HW_MEMSIZE};
29 size_t length =
sizeof(value);
31 if (-1 == sysctl(mib, 2, &value, &length, NULL, 0)) {
39 vm_size_t page_size = 0;
40 if (KERN_SUCCESS != host_page_size(mach_host_self(), &page_size)) {
44 vm_statistics64_data_t vm_stats;
45 mach_msg_type_number_t count = HOST_VM_INFO64_COUNT;
48 mach_host_self(), HOST_VM_INFO64,
reinterpret_cast<host_info64_t
>(&vm_stats), &count)) {
53 std::size_t available_pages =
static_cast<std::size_t
>(vm_stats.free_count)
54 +
static_cast<std::size_t
>(vm_stats.inactive_count);
56 return available_pages *
static_cast<std::size_t
>(page_size);
60#elif (defined(linux) || defined(__linux__) || defined(__linux)) \
61 || (defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) \
62 || defined(__OpenBSD__))
64 #include <sys/sysinfo.h>
77 std::ifstream meminfo(
"/proc/meminfo");
82 while (meminfo >> label >> value_kb >> unit) {
83 if (label ==
"MemAvailable:") {
84 return value_kb * 1024;
90 if (-1 == sysinfo(&info)) {
93 return static_cast<std::size_t
>(
info.freeram) *
static_cast<std::size_t
>(
info.mem_unit);
std::optional< std::size_t > getHostPhysicalMemory()
Get the amount of physical memory (RAM) available on the system, in bytes.
std::optional< std::size_t > getHostAvailableMemory()
Get the amount of physical memory (RAM) currently available on the system, in bytes.
void info(std::string module_name, Types... var2)
Prints a log message with multiple arguments.