Windows C++ / Checking Memory Size

Author Thomas Roccia (fr0gger)
Platform Windows
Language C++
Technique Checking Memory Size

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;
}

Created

March 19, 2023

Last Revised

April 22, 2024