现在的位置: 首页 > 综合 > 正文

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

2012年03月09日 ⁄ 综合 ⁄ 共 1092字 ⁄ 字号 评论关闭
// 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);

抱歉!评论已关闭.