您的位置:首页 > 其它

windows api 获取内存信息函数以及示例

2009-08-13 23:22 330 查看
 获取内存的信息: 
  #include   "stdafx.h" 
  
  #include   <windows.h> 
  #include   "stdio.h" 
  
  //   Use   to   change   the   divisor   from   Kb   to   Mb. 
  
  #define   DIV   1024 
  //   #define   DIV   1 
  
  char   *divisor   =   "K"; 
  
  #define   WIDTH   7 
  
  void   main(int   argc,   char   *argv[]) 
  { 
  MEMORYSTATUS   stat; 
  
  GlobalMemoryStatus   (&stat); 
  
  printf   ("The   MemoryStatus   structure   is   %ld   bytes   long./n", 
  stat.dwLength); 
  printf   ("It   should   be   %d./n",   sizeof   (stat)); 
  printf   ("%ld   percent   of   memory   is   in   use./n", 
  stat.dwMemoryLoad); 
  printf   ("There   are   %*ld   total   %sbytes   of   physical   memory./n", 
  WIDTH,   stat.dwTotalPhys/DIV,   divisor); 
  printf   ("There   are   %*ld   free   %sbytes   of   physical   memory./n", 
  WIDTH,   stat.dwAvailPhys/DIV,   divisor); 
  printf   ("There   are   %*ld   total   %sbytes   of   paging   file./n", 
  WIDTH,   stat.dwTotalPageFile/DIV,   divisor); 
  printf   ("There   are   %*ld   free   %sbytes   of   paging   file./n", 
  WIDTH,   stat.dwAvailPageFile/DIV,   divisor); 
  printf   ("There   are   %*lx   total   %sbytes   of   virtual   memory./n", 
  WIDTH,   stat.dwTotalVirtual/DIV,   divisor); 
  printf   ("There   are   %*lx   free   %sbytes   of   virtual   memory./n", 
  WIDTH,   stat.dwAvailVirtual/DIV,   divisor); 
  }
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  windows api structure div
相关文章推荐