2010年5月2日 星期日

[C++]計算程式記憶體使用量,Win API ::GetProcessMemoryInfo

#include "windows.h"
#include "stdio.h"
#include "psapi.h"

#pragma comment(lib, "strmiids.lib")
#pragma comment(lib, "psapi.lib")

int main(int argc, char *argv[]) { 

        PROCESS_MEMORY_COUNTERS pmc;
        /*

        your code here   

        */
        GetProcessMemoryInfo( GetCurrentProcess(), &pmc, sizeof(pmc)); //get memory usage

        cout <<"memory usage:" << pmc.PeakWorkingSetSize << endl; //unit in bytes
}

沒有留言: