MCPcopy Create free account
hub / github.com/Parchive/par2cmdline / GetTotalPhysicalMemory

Method GetTotalPhysicalMemory

src/commandline.cpp:959–991  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

957
958#ifdef _WIN32
959u64 CommandLine::GetTotalPhysicalMemory()
960{
961 u64 TotalPhysicalMemory = 0;
962
963 HMODULE hLib = ::LoadLibraryA("kernel32.dll");
964 if (NULL != hLib)
965 {
966 BOOL (WINAPI *pfn)(LPMEMORYSTATUSEX) = (BOOL (WINAPI*)(LPMEMORYSTATUSEX))::GetProcAddress(hLib, "GlobalMemoryStatusEx");
967
968 if (NULL != pfn)
969 {
970 MEMORYSTATUSEX mse;
971 mse.dwLength = sizeof(mse);
972 if (pfn(&mse))
973 {
974 TotalPhysicalMemory = mse.ullTotalPhys;
975 }
976 }
977
978 ::FreeLibrary(hLib);
979 }
980
981 if (TotalPhysicalMemory == 0)
982 {
983 MEMORYSTATUS ms;
984 ::ZeroMemory(&ms, sizeof(ms));
985 ::GlobalMemoryStatus(&ms);
986
987 TotalPhysicalMemory = ms.dwTotalPhys;
988 }
989
990 return TotalPhysicalMemory;
991}
992#elif defined(_SC_PHYS_PAGES) && defined(_SC_PAGESIZE)
993// POSIX compliant OSes, including OSX/MacOS and Cygwin. Also works for Linux.
994u64 CommandLine::GetTotalPhysicalMemory()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected