Memory Status
A C console program that prints system memory statistics — physical, page file, and virtual — using GlobalMemoryStatus.
The fastest way to get a snapshot of the machine's memory from C: fill a MEMORYSTATUS struct with GlobalMemoryStatus and read off the load percentage plus total/available figures for physical RAM, the page file, and the process's virtual address space. Useful in diagnostics, installers checking free space before work, or any tool that wants a one-line "how full is this box" answer.
#include <windows.h>
#include <stdio.h>
static MEMORYSTATUS ms;
int main(int argc, char *argv[])
{
ms.dwLength=sizeof(&ms);
GlobalMemoryStatus(&ms);
printf(" Memory Load %d \n",ms.dwMemoryLoad);
printf("Total Memory %d \n",ms.dwTotalPhys/1024/1024);
printf("Avail Memory %d \n",ms.dwAvailPhys/1024/1024);
printf("\n");
printf("Total Page Memory %d \n",ms.dwTotalPageFile/1024/1024);
printf("Avail Page Memory %d \n",ms.dwAvailPageFile/1024/1024);
printf("\n");
printf("Total Virtual Memory %d \n",ms.dwTotalVirtual/1024/1024);
printf("Avail Virtual Memory %d \n",ms.dwAvailVirtual/1024/1024);
return 0;
}
All values are printed in megabytes (bytes divided by 1024 twice). On modern systems prefer GetSystemMemoryStatusEx, which adds commit-charge fields and is not limited to 32-bit sizes.