(C++) Checking Memory Size by Thomas Roccia (fr0gger)

Created the Sunday 19 March 2023. Updated 1 week, 6 days ago.

Description:

This code uses the MEMORYSTATUSEX structure and the GlobalMemoryStatusEx function from the Windows API to retrieve information about the system's memory status, including the total physical memory and the available physical memory.

Code

            #include <windows.h>
#include <iostream>

int main() {
    MEMORYSTATUSEX memInfo;
    memInfo.dwLength = sizeof(MEMORYSTATUSEX);
    GlobalMemoryStatusEx(&memInfo);

    std::cout << "Total physical memory: " << memInfo.ullTotalPhys / 1024 / 1024 << " MB\n";
    std::cout << "Available physical memory: " << memInfo.ullAvailPhys / 1024 / 1024 << " MB\n";

    return 0;
}