.h
#ifndef EXTRAAPI_H
#define EXTRAAPI_H
class extraAPI
{
public:
extraAPI();
~extraAPI();
static void memoryinfo();
};
#endif // EXTRAAPI_H
.cpp
#include "windows.h"
#include "stdio.h"
#include "psapi.h"
// 需加入這兩個lib
#pragma comment(lib, "strmiids.lib")
#pragma comment(lib, "psapi.lib")
void extraAPI::memoryinfo()
{
PROCESS_MEMORY_COUNTERS pmc;
GetProcessMemoryInfo( GetCurrentProcess(), &pmc, sizeof(pmc)); //get memory usage
MEMORYSTATUSEX statex;
statex.dwLength = sizeof (statex);
GlobalMemoryStatusEx (&statex);
(statex.ullTotalPhys-statex.ullAvailPhys)/1024; // 全部已使用記憶體 3213064 (Kb)
pmc.WorkingSetSize/1024; // 此程式WorkingSet記憶體: 18832 (Kb)
}
沒有留言:
張貼留言