26 #include <sys/types.h> 28 #ifdef HAVE_SYS_SYSCTL_H 31 # include <sys/sysctl.h> 34 #ifdef HAVE_VM_VM_PARAM_H 35 # include <vm/vm_param.h> 37 #ifdef HAVE_SYS_VMMETER_H 38 # include <sys/vmmeter.h> 40 #ifdef HAVE_SYS_SYSMP_H 41 # include <sys/sysmp.h> 43 #ifdef HAVE_SYS_SYSINFO_H 44 # include <sys/sysinfo.h> 46 #ifdef HAVE_SYS_PSTAT_H 47 # include <sys/pstat.h> 62 long long pagesize = 1;
64 #if defined(_SC_PAGESIZE) && defined(_SC_PHYS_PAGES) 72 pagesize = sysconf(_SC_PAGESIZE);
73 pages = sysconf(_SC_PHYS_PAGES);
74 #elif defined HAVE_PSTAT_GETDYNAMIC 76 struct pst_dynamic info;
77 if (pstat_getdynamic(&info,
sizeof(info), 1, 0) == 1) {
78 pagesize = getpagesize();
79 pages = info.psd_free;
81 #elif defined CTL_VM && (defined VM_TOTAL || defined VM_METER) 83 struct vmtotal vm_info;
84 static const int mib[2] = {
92 size_t len =
sizeof(vm_info);
93 if (sysctl(mib, 2, &vm_info, &len, NULL, 0) == 0) {
94 pagesize = getpagesize();
95 pages = vm_info.t_free;
98 if (pagesize > 0 && pages > 0) {
99 return pages * pagesize;
103 MEMORYSTATUSEX statex;
104 statex.dwLength =
sizeof(statex);
105 GlobalMemoryStatusEx(&statex);
106 return statex.ullAvailPhys;
118 long long pagesize = 1;
119 long long pages = -1;
120 #if defined(_SC_PAGESIZE) && defined(_SC_AVPHYS_PAGES) 122 pagesize = sysconf(_SC_PAGESIZE);
123 pages = sysconf(_SC_PHYS_PAGES);
124 #elif defined HAVE_PSTAT_GETDYNAMIC 126 struct pst_dynamic info;
127 if (pstat_getdynamic(&info,
sizeof(info), 1, 0) == 1) {
128 pagesize = getpagesize();
131 #elif defined CTL_VM && (defined VM_TOTAL || defined VM_METER) 133 struct vmtotal vm_info;
134 static const int mib[2] = {
142 size_t len =
sizeof(vm_info);
143 if (sysctl(mib, 2, &vm_info, &len, NULL, 0) == 0) {
144 pagesize = getpagesize();
145 pages = vm_info.t_rm;
148 if (pagesize > 0 && pages > 0) {
149 return pages * pagesize;
153 MEMORYSTATUSEX statex;
154 statex.dwLength =
sizeof(statex);
155 GlobalMemoryStatusEx(&statex);
156 return statex.ullTotalPhys;
long long get_total_physical_memory()
Determine how much physical memory there is.
include <windows.h> without all the bloat and damage.
<unistd.h>, but with compat.
determine how much free physical memory there is.
long long get_free_physical_memory()
Determine how much free physical memory there is.