Created
September 1, 2023 21:02
-
-
Save AMZN-alexpete/8ab0cb06d260d8a2bbd9b6f35b00236c to your computer and use it in GitHub Desktop.
Retrieve physically installed system memory (Windows)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| m_value = 0; | |
| HMODULE kernel32Handle = ::GetModuleHandleW(L"Kernel32.dll"); | |
| if (kernel32Handle) | |
| { | |
| using Func = BOOL(WINAPI*)(_Out_ PULONGLONG TotalMemoryInKilobytes); | |
| auto getPhysicallyInstalledSystemMemoryFunc = | |
| reinterpret_cast<Func>(::GetProcAddress(kernel32Handle, "GetPhysicallyInstalledSystemMemory")); | |
| if (getPhysicallyInstalledSystemMemoryFunc) | |
| { | |
| // Physical RAM is returned in KB | |
| constexpr float div = 1024.0 * 1024.0; | |
| ULONGLONG ullTotalPhys = 0; | |
| if (getPhysicallyInstalledSystemMemoryFunc(&ullTotalPhys)) | |
| { | |
| m_value = aznumeric_cast<float>(ullTotalPhys) / div; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment