C語言實(shí)現(xiàn)獲取內(nèi)存信息并輸出的實(shí)例
更新時(shí)間:2017年03月25日 14:33:28 投稿:lqh
這篇文章主要介紹了C語言實(shí)現(xiàn)獲取內(nèi)存信息并輸出的實(shí)例的相關(guān)資料,需要的朋友可以參考下
C語言實(shí)現(xiàn)獲取內(nèi)存信息并輸出的實(shí)例
實(shí)現(xiàn)實(shí)例代碼:
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) //給數(shù)組生成數(shù)據(jù),用于隨即查找 { time_t t; srand(time(&t)); for (int i=0;i<length;i++) { a[i]=rand()%length; } } void printData(int a[],int length) //打印數(shù)字,到控制臺(tái),每五個(gè)換一行 { 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("內(nèi)存使用: %8lf \n",MemorySize); //WorkingSetSize The current working set size, in bytes. return MemorySize; } void writeRecordtime(unsigned rTime)//將程序結(jié)果運(yùn)行時(shí)間寫入文件 { 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; }
感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
相關(guān)文章
基于C++11實(shí)現(xiàn)手寫線程池的示例代碼
在實(shí)際的項(xiàng)目中,使用線程池是非常廣泛的,本文主要介紹了基于C++11實(shí)現(xiàn)手寫線程池的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2024-08-08C++?QT實(shí)現(xiàn)獲取本機(jī)網(wǎng)卡信息
這篇文章主要為大家詳細(xì)介紹了如何利用qt自帶的QNetworkInterface接口以及c++Iphlpapi庫,獲取當(dāng)前windows電腦下的網(wǎng)卡信息,需要的可以參考下2024-01-01C++ OpenCV實(shí)現(xiàn)圖像雙三次插值算法詳解
圖像雙三次插值的原理,就是目標(biāo)圖像的每一個(gè)像素都是由原圖上相對(duì)應(yīng)點(diǎn)周圍的4x4=16個(gè)像素經(jīng)過加權(quán)之后再相加得到的。本文主要介紹了通過C++ OpenCV實(shí)現(xiàn)圖像雙三次插值算法,需要的可以參考一下2021-12-12C++實(shí)現(xiàn)LeetCode(17.電話號(hào)碼的字母組合)
這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode(17.電話號(hào)碼的字母組合),本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-07-07C語言數(shù)據(jù)結(jié)構(gòu)二叉樹先序、中序、后序及層次四種遍歷
這篇文章主要介紹了C語言數(shù)據(jù)結(jié)構(gòu)二叉樹先序、中序、后序及層次四種遍歷方式,具有一定的知識(shí)性參考價(jià)值,需要的小伙伴可以先看一下2022-02-02