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_SYSMP 76 struct rminfo meminfo;
77 if (sysmp(MP_SAGET, MPSA_RMINFO, &meminfo,
sizeof(meminfo)) == 0) {
78 pagesize = sysconf(_SC_PAGESIZE);
79 pages = meminfo.availrmem;
81 #elif defined HAVE_PSTAT_GETDYNAMIC 83 struct pst_dynamic info;
84 if (pstat_getdynamic(&info,
sizeof(info), 1, 0) == 1) {
85 pagesize = getpagesize();
86 pages = info.psd_free;
88 #elif defined CTL_VM && (defined VM_TOTAL || defined VM_METER) 90 struct vmtotal vm_info;
91 static const int mib[2] = {
99 size_t len =
sizeof(vm_info);
100 if (sysctl(mib, 2, &vm_info, &len, NULL, 0) == 0) {
101 pagesize = getpagesize();
102 pages = vm_info.t_free;
105 if (pagesize > 0 && pages > 0) {
106 return pages * pagesize;
110 MEMORYSTATUSEX statex;
111 statex.dwLength =
sizeof(statex);
112 GlobalMemoryStatusEx(&statex);
113 return statex.ullAvailPhys;
125 long long pagesize = 1;
126 long long pages = -1;
127 #if defined(_SC_PAGESIZE) && defined(_SC_AVPHYS_PAGES) 129 pagesize = sysconf(_SC_PAGESIZE);
130 pages = sysconf(_SC_PHYS_PAGES);
131 #elif defined HAVE_SYSMP 133 struct rminfo meminfo;
134 if (sysmp(MP_SAGET, MPSA_RMINFO, &meminfo,
sizeof(meminfo)) == 0) {
135 pagesize = sysconf(_SC_PAGESIZE);
136 pages = meminfo.physmem;
138 #elif defined HAVE_PSTAT_GETDYNAMIC 140 struct pst_dynamic info;
141 if (pstat_getdynamic(&info,
sizeof(info), 1, 0) == 1) {
142 pagesize = getpagesize();
145 #elif defined CTL_VM && (defined VM_TOTAL || defined VM_METER) 147 struct vmtotal vm_info;
148 static const int mib[2] = {
156 size_t len =
sizeof(vm_info);
157 if (sysctl(mib, 2, &vm_info, &len, NULL, 0) == 0) {
158 pagesize = getpagesize();
159 pages = vm_info.t_rm;
162 if (pagesize > 0 && pages > 0) {
163 return pages * pagesize;
167 MEMORYSTATUSEX statex;
168 statex.dwLength =
sizeof(statex);
169 GlobalMemoryStatusEx(&statex);
170 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.