| 209 | |
| 210 | |
| 211 | qindex mem_tryGetLocalRamCapacityInBytes() { |
| 212 | #if defined(__linux__) |
| 213 | struct sysinfo info; |
| 214 | if (sysinfo(&info) == 0) |
| 215 | return (qindex) info.totalram * info.mem_unit; |
| 216 | #elif defined(__APPLE__) |
| 217 | int mib[2] = {CTL_HW, HW_MEMSIZE}; |
| 218 | int64_t memsize = 0; |
| 219 | size_t len = sizeof(memsize); |
| 220 | if (sysctl(mib, 2, &memsize, &len, NULL, 0) == 0 && memsize > 0) |
| 221 | return (qindex) memsize; |
| 222 | #elif defined(_WIN32) |
| 223 | MEMORYSTATUSEX statex; |
| 224 | statex.dwLength = sizeof(statex); |
| 225 | if (GlobalMemoryStatusEx(&statex)) |
| 226 | return (qindex) statex.ullTotalPhys; |
| 227 | #endif |
| 228 | // fallback: throw exception |
| 229 | throw (mem::COULD_NOT_QUERY_RAM) false; |
| 230 | } |
| 231 | |
| 232 | |
| 233 |
no test coverage detected