Introduction
I created this class because I need it to trace some objects in a multithreaded application. Got a lot of problems because of objects used before actual creation and objects referenced after destruction. Of course, you will not have encountered this kind of problem in small applications, but if things get really complex... then you might consider using this from the start.
Using the Code
Using this code is a simple task and you don't have to think about it later. Just set it and forget it. In /RELEASE mode, you will not have any problem, because the CDebugTrace
objects will be empty.
First, add debugtrace.h and debugtrace.cpp to your project. After this, add an CDebugTrace
object to classes that are important for your project (I advise you to use it for all your classes). Below is a sample usage of this class:
#include "debugtrace.h"
class MyClass
{
CDebugTrace Trace;
public:
MyClass();
~MyClass();
void SomeMethod(void);
...
};
#include "myclass.h"
MyClass::MyClass()
: Trace( "MyClass" )
{
...
}
MyClass::~MyClass()
{
...
}
void MyClass::SomeMethod()
{
Trace.Print("entered SomeMethod" );
...
}
If you use it like this, you will know when that object was created or destroyed and the life of it.
You can also use CDebugTrace
with functions, like this:
void SomeFunction( void )
{
CDebugTrace Trace( "SomeFunction" );
...
}
This way, you know when that function executes and how much it took to run.
Points of Interest
This class helps me a lot and a lot of other things can be added. For example, CPU and memory stats would probably help too.
History
- 21st February, 2005: Version 1.0
Well, I have to begin somewhere. This is my first article.
License
This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.
A list of licenses authors might use can be found here.