Search code examples
cvisual-studio-2010memoryramsysinfo

How to determine installed memory on x64 machine using visual studio windows 7


Is there a way to determine the amount of memory installed on a computer running 64bit windows 7, using VS2010 C?

The app I am running is a Windows 64bit app, with a UI written in c#, which calls a dll written in C. The call to get the installed memory has to be done from the C code, not the c#.


Solution

  • Use the GlobalMemoryStatusEx function:

    MEMORYSTATUSEX memInfo = {sizeof(memInfo)};
    if (GlobalMemoryStatusEx(&memInfo))
    {
        printf("Total installed physical memory: %lld bytes\n", memInfo.ullTotalPhys);
    }