MCPcopy Create free account
hub / github.com/DigitalInBlue/Celero / GetRAMSystemTotal

Method GetRAMSystemTotal

src/Memory.cpp:128–161  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

126}
127
128int64_t celero::GetRAMSystemTotal()
129{
130#ifdef _WIN32
131 MEMORYSTATUSEX memInfo;
132 memInfo.dwLength = sizeof(MEMORYSTATUSEX);
133 GlobalMemoryStatusEx(&memInfo);
134 return static_cast<int64_t>(memInfo.ullTotalPhys) + static_cast<int64_t>(memInfo.ullTotalVirtual);
135#elif defined(__unix__) || defined(__unix) || defined(unix)
136 // Prefer sysctl() over sysconf() except sysctl() HW_REALMEM and HW_PHYSMEM
137 // return static_cast<int64_t>(sysconf(_SC_PHYS_PAGES)) * static_cast<int64_t>(sysconf(_SC_PAGE_SIZE));
138 struct sysinfo memInfo;
139 sysinfo(&memInfo);
140 int64_t total = memInfo.totalram;
141 total += memInfo.totalswap;
142 total += memInfo.totalhigh;
143 return total * static_cast<int64_t>(memInfo.mem_unit);
144#elif defined(__APPLE__)
145 int mib[2];
146 mib[0] = CTL_HW;
147 mib[1] = HW_MEMSIZE;
148
149 int64_t memInfo{0};
150 auto len = sizeof(memInfo);
151
152 if(sysctl(mib, 2, &memInfo, &len, nullptr, 0) == 0)
153 {
154 return memInfo;
155 }
156
157 return -1;
158#else
159 return -1;
160#endif
161}
162
163int64_t celero::GetRAMSystemAvailable()
164{

Callers

nothing calls this directly

Calls 1

sysinfoClass · 0.85

Tested by

no test coverage detected