国产探花免费观看_亚洲丰满少妇自慰呻吟_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; } 

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

 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 突泉县| 峨眉山市| 乐东| 永宁县| 西和县| 和平县| 睢宁县| 陆丰市| 禹州市| 北碚区| 云龙县| 酒泉市| 治多县| 德兴市| 顺昌县| 金坛市| 鱼台县| 石首市| 乌恰县| 抚松县| 德江县| 犍为县| 无极县| 镇江市| 凤山县| 甘肃省| 酒泉市| 高要市| 修武县| 洞口县| 汝南县| 吴江市| 黔西| 合川市| 新昌县| 湛江市| 滦平县| 鸡东县| 江口县| 诸城市| 宁蒗|