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

首頁 > 編程 > C++ > 正文

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

2020-05-23 13:49:08
字體:
來源:轉載
供稿:網友

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; } 

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

 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 辰溪县| 梁平县| 合山市| 中牟县| 玉门市| 沂源县| 太白县| 通化市| 象山县| 井冈山市| 图木舒克市| 盱眙县| 全州县| 佛教| 石家庄市| 临夏县| 旌德县| 琼中| 黎川县| 紫阳县| 丰镇市| 淅川县| 易门县| 阿城市| 凤凰县| 嘉兴市| 元氏县| 太仆寺旗| 休宁县| 周口市| 栾川县| 且末县| 镇远县| 蕉岭县| 威信县| 浦江县| 阜新市| 灌云县| 灌云县| 宁晋县| 广安市|