获取内存使用率等相关信息

// Use to convert bytes to KB
#define DIV 1024
// Specify the width of the field in which to print the numbers. 
// The asterisk in the format specifier "%*I64d" takes an integer 
// argument and uses it to pad and right justify the number.
#define WIDTH 7 

////memory information///

 
 MEMORYSTATUSEX statex;
 statex.dwLength = sizeof (statex);
 GlobalMemoryStatusEx (&statex);
 printf("tyc,%d",statex.dwMemoryLoad);
 printf ("There is %*ld percent of memory in use.\n",
  WIDTH, statex.dwMemoryLoad);
 printf ("There are %*I64d total Kbytes of physical memory.\n",
  WIDTH, statex.ullTotalPhys/DIV);
 printf ("There are %*I64d free Kbytes of physical memory.\n",
  WIDTH, statex.ullAvailPhys/DIV);
 printf ("There are %*I64d total Kbytes of paging file.\n",
  WIDTH, statex.ullTotalPageFile/DIV);
 printf ("There are %*I64d free Kbytes of paging file.\n",
  WIDTH, statex.ullAvailPageFile/DIV);
 printf ("There are %*I64d total Kbytes of virtual memory.\n",
  WIDTH, statex.ullTotalVirtual/DIV);
 printf ("There are %*I64d free Kbytes of virtual memory.\n",
  WIDTH, statex.ullAvailVirtual/DIV);
 // Show the amount of extended memory available.
 printf ("There are %*I64d free Kbytes of extended memory.\n",
  WIDTH, statex.ullAvailExtendedVirtual/DIV);

你可能感兴趣的:(内存)