国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C > 正文

C語言實現獲取內存信息并輸出的實例

2020-01-26 14:12:50
字體:
來源:轉載
供稿:網友

C語言實現獲取內存信息并輸出的實例

實現實例代碼:

headfile.h

#include <stdio.h> #include <stdlib.h> #include <time.h>  #define TRUE 1 #define FALSE 0 #define MAX 10000  typedef int KeyType; typedef int OtherType;  typedef struct {   KeyType key;   OtherType other_data; }RecordType; 

seek.cpp

#include "stdafx.h" #include "headfile.h" #include "windows.h" #include "conio.h "  #include"WinBase.h" #include "Psapi.h"  #pragma once #pragma message("Psapi.h --> Linking with Psapi.lib") #pragma comment(lib,"Psapi.lib")  int Data[MAX]={0};  void produceData(int a[],int length)    //給數組生成數據,用于隨即查找 {   time_t t;   srand(time(&t));   for (int i=0;i<length;i++)   {     a[i]=rand()%length;   } }  void printData(int a[],int length)   //打印數字,到控制臺,每五個換一行 {   for (int i=0;i<length;i++)   {     printf("%8d",a[i]);     if (0==i%5)     {       printf("/n");     }   } }  double showMemoryInfo()   {     double MemorySize;         //單位MB   HANDLE handle=GetCurrentProcess();      PROCESS_MEMORY_COUNTERS pmc;     GetProcessMemoryInfo(handle,&pmc,sizeof(pmc));    MemorySize=pmc.WorkingSetSize/1024;    printf("內存使用: %8lf /n",MemorySize);  //WorkingSetSize The current working set size, in bytes.    return MemorySize; }   void writeRecordtime(unsigned rTime)//將程序結果運行時間寫入文件 {   FILE *fpRecord=NULL;     char *s="your programm running time is:  ";   char *c="ms  ";    if((fpRecord=fopen("record.txt","wt+"))==NULL)    {      printf("Cannot open file strike any key exit!");      getchar();      exit(1);    }     fprintf( fpRecord, "%s", s);   fprintf( fpRecord, "%d", rTime);   fprintf( fpRecord, "%s", c);    fprintf( fpRecord, "/n");   fprintf( fpRecord, "your programm use %fMB size of memory!!!", showMemoryInfo());    fclose(fpRecord);  }  int _tmain(int argc, _TCHAR* argv[]) {   produceData(Data,MAX);   printData(Data,MAX);   getchar();   return 0; } 

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 象州县| 英吉沙县| 马尔康县| 南乐县| 保山市| 大丰市| 广东省| 河东区| 南安市| 金华市| 商洛市| 汕头市| 嘉善县| 玛多县| 宾川县| 大英县| 韶关市| 当雄县| 桦甸市| 钦州市| 台江县| 建始县| 谷城县| 长治县| 抚州市| 涟源市| 两当县| 社会| 大港区| 邮箱| 台中市| 防城港市| 瑞丽市| 乐安县| 台中县| 修水县| 绵竹市| 临潭县| 梁河县| 安阳县| 修水县|