欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網!

C語言

當前位置:主頁 > 軟件編程 > C語言 >

C語言實現(xiàn)獲取內存信息并輸出的實例

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C語言|點擊: 次

C語言實現(xiàn)獲取內存信息并輸出的實例

實現(xiàn)實例代碼:

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ù)字,到控制臺,每五個換一行 
{ 
  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; 
} 

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

網頁制作CMS教程網絡編程軟件編程腳本語言數(shù)據(jù)庫服務器

如果侵犯了您的權利,請與我們聯(lián)系,我們將在24小時內進行處理、任何非本站因素導致的法律后果,本站均不負任何責任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網 版權所有