#include "stdafx.h"
#include <cstring>
#include <Windows.h>
#include <psapi.h>
#pragma comment(lib,"psapi.lib")
typedef long long int64_t;
typedef unsigned long long uint64_t;
int get_memory_usage(uint64_t* mem, uint64_t* vmem)
{
PROCESS_MEMORY_COUNTERS pmc;
if(GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc)))
{
if(mem) *mem = pmc.WorkingSetSize;
if(vmem) *vmem = pmc.PagefileUsage;
return 0;
}
return -1;
}
int main(int argc, char* argv[])
{
time_t timeBegin,timeEnd;//测试时间
uint64_t mem, vmem, r, w; //测试内存占用率
int oriSize;//源数据大小
int memSize;//内存大小
float times;
//程序运行代码
get_memory_usage(&mem, &vmem);
oriSize=lengthOfdata/(1024*512);
memSize=mem/(1024*1024);
times=float(memSize)/oriSize;
printf("内存使用: %u 字节\n", mem);
printf("虚拟内存使用: %u 字节\n", vmem);
printf("原始数据大小%d MB\n",oriSize);
printf("内存使用:%d MB\n",memSize);
printf("倍数 %.2f \n",times);
return 0;
}
}