1

I am looking for method that return available RAM and for this moment I have found only this answer

https://stackoverflow.com/a/2513561/5709159

#include <windows.h>

unsigned long long getTotalSystemMemory()
{
    MEMORYSTATUSEX status;
    status.dwLength = sizeof(status);
    GlobalMemoryStatusEx(&status);
    return status.ullTotalPhys;
}

But this method return Total memory. So, I need to find out how to get RAM that currently in usage or method than directly return available RAM.

How to do it?

EDIT

I need to know amount of available RAM in order to present it on my statistic form. I have a field Available RAM :

Sirop4ik
  • 4,543
  • 2
  • 54
  • 121
  • Like: https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/ns-sysinfoapi-memorystatusex says dwMemoryLoad gives you approx. percantage of used physical memory. With that information you could calculate the needed value. Or better do what @adrian mole answered. :) – user743414 Aug 13 '20 at 08:53
  • 1
    @DevSolar added to question – Sirop4ik Aug 13 '20 at 08:53

1 Answers1

4

You can use the same call to GlobalMemoryStatusEx() and examine the .ullAvailPhys field of the MEMORYSTATUSEX structure to get the amount of available physical memory. The difference between this and the .ullTotalPhys value will be how much physical memory is in use.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83