| 302 | |
| 303 | |
| 304 | std::size_t |
| 305 | getAmountFreePhysicalRAM() |
| 306 | { |
| 307 | #if defined(_WIN32) |
| 308 | ///On Windows, but not Cygwin, the new GlobalMemoryStatusEx( ) function fills a 64-bit |
| 309 | ///safe MEMORYSTATUSEX struct with information about physical and virtual memory. Structure fields include: |
| 310 | MEMORYSTATUSEX statex; |
| 311 | statex.dwLength = sizeof (statex); |
| 312 | GlobalMemoryStatusEx (&statex); |
| 313 | |
| 314 | return statex.ullAvailPhys; |
| 315 | #elif defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__) |
| 316 | struct sysinfo memInfo; |
| 317 | sysinfo (&memInfo); |
| 318 | long long totalAvailableRAM = memInfo.freeram; |
| 319 | totalAvailableRAM *= memInfo.mem_unit; |
| 320 | |
| 321 | return totalAvailableRAM; |
| 322 | #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__) |
| 323 | // and http://source.winehq.org/git/wine.git/blob/HEAD:/dlls/kernel32/heap.c |
| 324 | unsigned long long ullAvailPhys; |
| 325 | unsigned long long ullTotalPhys = 0; |
| 326 | uint64_t total; |
| 327 | #ifdef __APPLE__ |
| 328 | unsigned int val; |
| 329 | #else |
| 330 | unsigned long val; |
| 331 | #endif |
| 332 | int mib[2]; |
| 333 | size_t size_sys; |
| 334 | #ifdef HW_MEMSIZE |
| 335 | uint64_t val64 = 0; |
| 336 | #endif |
| 337 | #if 0 |
| 338 | #ifdef VM_SWAPUSAGE |
| 339 | struct xsw_usage swap; |
| 340 | #endif |
| 341 | #endif |
| 342 | |
| 343 | total = 0; |
| 344 | ullAvailPhys = 0; |
| 345 | |
| 346 | mib[0] = CTL_HW; |
| 347 | #ifdef HW_MEMSIZE |
| 348 | mib[1] = HW_MEMSIZE; |
| 349 | size_sys = sizeof(val64); |
| 350 | if (!sysctl(mib, 2, &val64, &size_sys, NULL, 0) && size_sys == sizeof(val64) && val64) |
| 351 | total = val64; |
| 352 | #endif |
| 353 | |
| 354 | #if defined(__MACH__) |
| 355 | // see http://opensource.apple.com/source/system_cmds/system_cmds-498.2/vm_stat.tproj/vm_stat.c |
| 356 | { |
| 357 | host_name_port_t host = mach_host_self(); |
| 358 | mach_msg_type_number_t count; |
| 359 | |
| 360 | #ifdef HOST_VM_INFO64_COUNT |
| 361 | vm_size_t page_size; |
no test coverage detected