how to print application memory
-
Hi All, i have an MFC application receive event message and based on the message type to new "Order" object. the created object stored in a map and never delete thro' the application cycle. my "Order" class size only < 1k byte. however, the application memory grow as 100k per order inputted. i added the CRT memory leak statement (use _CrtMemDifference, _CrtMemCheckpoint) to see the difference after executed function for each event. the result can show the object size (Order class) i created. however, the 100K grow rate still not able to show. questions: A) i wonder i dont know what reflect in those functions. anyone have idea on this? B) more effective question is how can i print the memory size of my application? so, i can check the memory usage difference for each big function call and drill down the problematic function. like this : printf("b4 handler"); printMemSize(); BigHandler(); printf("after handler"); printMemSize(); any reply will be highly appreciated! thanks! jim
-
Hi All, i have an MFC application receive event message and based on the message type to new "Order" object. the created object stored in a map and never delete thro' the application cycle. my "Order" class size only < 1k byte. however, the application memory grow as 100k per order inputted. i added the CRT memory leak statement (use _CrtMemDifference, _CrtMemCheckpoint) to see the difference after executed function for each event. the result can show the object size (Order class) i created. however, the 100K grow rate still not able to show. questions: A) i wonder i dont know what reflect in those functions. anyone have idea on this? B) more effective question is how can i print the memory size of my application? so, i can check the memory usage difference for each big function call and drill down the problematic function. like this : printf("b4 handler"); printMemSize(); BigHandler(); printf("after handler"); printMemSize(); any reply will be highly appreciated! thanks! jim
Maybe try something like this:
// Add this block of code to
ONE
cpp source file#ifdef _DEBUG
class _MemStateCheck
{
public:
CMemoryState oldMemState, newMemState, diffMemState;\_MemStateCheck(); ~\_MemStateCheck();
};
_MemStateCheck::_MemStateCheck()
{
oldMemState.Checkpoint();
}_MemStateCheck::~_MemStateCheck()
{
newMemState.Checkpoint();
if( diffMemState.Difference( oldMemState, newMemState ) )
{
TRACE( "************************\n" );
TRACE( "Memory leaks Detected\n" );
TRACE( "************************\n" );
diffMemState.DumpStatistics();
diffMemState.DumpAllObjectsSince();
}
else
{
TRACE( "************************\n" );
TRACE( "No memory leaks Detected\n" );
TRACE( "************************\n" );
}
}_MemStateCheck MemCheckObj;
#endif //#ifdef _DEBUG
// Add this to the top of
EVERY
cpp source file (under the #includes)#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endifThe code in the first block checks for leaks between the construction and destruction of the static _MemStateCheck MemCheckObj variable. It also shows how you can get memory checkpoints and dump the difference between them to the debugger output window. The code in the second block sets the use of the debug new operator and insures file/linenumber info is available so the leak dump has more useful information. Mark
This episode brought to you by the number 5
-
Maybe try something like this:
// Add this block of code to
ONE
cpp source file#ifdef _DEBUG
class _MemStateCheck
{
public:
CMemoryState oldMemState, newMemState, diffMemState;\_MemStateCheck(); ~\_MemStateCheck();
};
_MemStateCheck::_MemStateCheck()
{
oldMemState.Checkpoint();
}_MemStateCheck::~_MemStateCheck()
{
newMemState.Checkpoint();
if( diffMemState.Difference( oldMemState, newMemState ) )
{
TRACE( "************************\n" );
TRACE( "Memory leaks Detected\n" );
TRACE( "************************\n" );
diffMemState.DumpStatistics();
diffMemState.DumpAllObjectsSince();
}
else
{
TRACE( "************************\n" );
TRACE( "No memory leaks Detected\n" );
TRACE( "************************\n" );
}
}_MemStateCheck MemCheckObj;
#endif //#ifdef _DEBUG
// Add this to the top of
EVERY
cpp source file (under the #includes)#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endifThe code in the first block checks for leaks between the construction and destruction of the static _MemStateCheck MemCheckObj variable. It also shows how you can get memory checkpoints and dump the difference between them to the debugger output window. The code in the second block sets the use of the debug new operator and insures file/linenumber info is available so the leak dump has more useful information. Mark
This episode brought to you by the number 5
Thanks! Mark. This is what i did but i used the _CRTMemXXXX function from crtdbg.h. i guess your CMemoryState is from MFC. I have i question. If there is no memory leak, but i want to print the app's allocated memory size (sth like the "memory" column in task manager). Any function can serve this purpose? thanks! jim
-
Thanks! Mark. This is what i did but i used the _CRTMemXXXX function from crtdbg.h. i guess your CMemoryState is from MFC. I have i question. If there is no memory leak, but i want to print the app's allocated memory size (sth like the "memory" column in task manager). Any function can serve this purpose? thanks! jim
Maybe this: Collecting Memory Usage Information For a Process[^] Mark
This episode brought to you by the number 5
-
Maybe this: Collecting Memory Usage Information For a Process[^] Mark
This episode brought to you by the number 5