• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

C语言实现获取内存信息并输出的实例

c语言 搞代码 4年前 (2022-01-06) 39次浏览 已收录 0个评论

这篇文章主要介绍了C语言实现获取内存信息并输出的实例的相关资料,需要的朋友可以参考下

C语言实现获取内存信息并输出的实例

实现实例代码:

headfile.h

 #include  #include  #include  #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" #inc<em style="color:transparent">来源[email protected]搞@^&代*@码网</em>lude "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; } 

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

以上就是C语言实现获取内存信息并输出的实例的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:C语言实现获取内存信息并输出的实例
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址