50 #elif defined ARCH_DARWIN 51 #include <mach/mach_host.h> 52 #include <mach/vm_statistics.h> 53 #include <sys/sysctl.h> 54 #include <sys/types.h> 64 void parseMeminfo(uint64_t& _total, uint64_t& _free, uint64_t& _buffer)
68 unsigned long long memcache, memfree, total, free, buffer;
70 FILE* info = fopen(
"/proc/meminfo",
"r");
71 if(fscanf (info,
"MemTotal: %19llu kB MemFree: %19llu kB Buffers: %19llu kB Cached: %19llu kB",&total, &memfree, &buffer, &memcache) < 4)
74 info = fopen(
"/proc/meminfo",
"r");
76 if(fscanf(info,
"MemTotal: %19llu kB MemFree: %19llu kB MemAvailable: %19llu kB Buffers: %19llu kB Cached: %19llu kB",&total, &memfree, &free, &buffer, &memcache) < 5)
85 free = memfree + (buffer + memcache);
91 free = memfree + (buffer + memcache);
104 void MemoryInfoUpdate(MemoryVacancy & _outMemoryVacancy) {
107 _outMemoryVacancy.totalRamMB = 0;
108 _outMemoryVacancy.freeRamMB = 0;
109 _outMemoryVacancy.bufferRamMB = 0;
112 #ifdef WIN32 //Windows 116 ms.dwLength =
sizeof(ms);
118 GlobalMemoryStatusEx(&ms);
120 _outMemoryVacancy.totalRamMB = ms.ullTotalPhys / 1024 / 1024;
121 _outMemoryVacancy.freeRamMB = ms.ullAvailPhys / 1024 / 1024;
123 #elif defined ARCH_DARWIN // Apple (sadly cant query free memory) 124 mach_msg_type_number_t count = HOST_VM_INFO_COUNT;
125 vm_statistics_data_t vmstat;
126 if(KERN_SUCCESS != host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmstat, &count))
138 if( sysctl(mib, 2, &physical_memory, &length, NULL, 0) == -1 )
143 _outMemoryVacancy.totalRamMB = physical_memory / 1024 / 1024;
144 unsigned long active = vmstat.active_count * PAGE_SIZE / 1024 / 1024;
145 _outMemoryVacancy.freeRamMB = _outMemoryVacancy.totalRamMB - active;
146 _outMemoryVacancy.bufferRamMB =0;
152 parseMeminfo(total, free, buffer);
155 _outMemoryVacancy.totalRamMB = total / 1024;
156 _outMemoryVacancy.freeRamMB = free / 1024;
157 _outMemoryVacancy.bufferRamMB = buffer / 1024;
164 MemoryInfoUpdate(vac);
165 return vac.freeRamMB;
171 MemoryInfoUpdate(vac);
172 return vac.totalRamMB;
178 MemoryInfoUpdate(vac);
179 return vac.bufferRamMB;
unsigned long long uint64_t