Thursday, June 27, 2013

Get memory usage info

In this post I will show you how to log your current memory usage in a process. Our main function to get required information is “GetProcessMemoryInfo()” function, which is defined in psapi.h(Process Status API). After you include psapi.h in your code file, you have to link psapi.lib to your project. Otherwise you will get a linker error.
#include "psapi.h"

  PPROCESS_MEMORY_COUNTERS pMemCountr = new PROCESS_MEMORY_COUNTERS;
    if(GetProcessMemoryInfo(GetCurrentProcess(),pMemCountr,
             sizeof(PROCESS_MEMORY_COUNTERS)))
{
printf("%l",pMemCountr->PagefileUsage/1024)
}
    delete pMemCountr;

No comments:

Post a Comment