MCPcopy Create free account
hub / github.com/QuEST-Kit/QuEST / mem_tryGetLocalRamCapacityInBytes

Function mem_tryGetLocalRamCapacityInBytes

quest/src/core/memory.cpp:211–230  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

209
210
211qindex 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

Callers 8

assertQuregFitsInCpuMemFunction · 0.85
assertMatrixFitsInCpuMemFunction · 0.85
printCpuInfoFunction · 0.85
printQuregSizeLimitsFunction · 0.85

Calls 1

sysinfoClass · 0.85

Tested by

no test coverage detected