This code is used to obtain the process memory usage in the class constructor, and the amount of changes in the process memory usage is printed during the analysis.
Class CAutoMem
{
Public:
CAutoMem (char * vInfo): strMem (vInfo ){
Init ();
}
~ CAutoMem (){
PrintMem ();
}
Void Init ()
{
DwPrcID = GetCurrentProcess ();
PROCESS_MEMORY_COUNTERS pmc;
GetProcessMemoryInfo (HANDLE) dwPrcID, & pmc, sizeof (pmc ));
DwMemSize = pmc. WorkingSetSize;
}
Void PrintMem ()
{
PROCESS_MEMORY_COUNTERS pmc;
GetProcessMemoryInfo (HANDLE) dwPrcID, & pmc, sizeof (pmc ));
If (pmc. WorkingSetSize> dwMemSize)
{
If (pmc. WorkingSetSize-dwMemSize> 1024)
{
Printf ("% s memory application % d \ n", strMem. c_str (), (pmc. WorkingSetSize-dwMemSize)/1024 );
}
}
Else
{
If (pmc. WorkingSetSize-dwMemSize> 1024)
{
Printf ("% s memory release % d \ n", strMem. c_str (), (dwMemSize-pmc. WorkingSetSize)/1024 );
}
}
}
Public:
String strMem;
HANDLE dwPrcID;
DWORD dwMemSize;
};
This article is from the "Amu Xue" blog and will not be reproduced!