Original Post
I''m trying to write a little profiler class for use in my programs, as I only have VC6 standard - no built-in profiler. Anyway, when I want to use the profiling, I have to create a new instance of the class at the top of each of the functions that will be profiled. When I delete the class at the end of the function, it will save the data it has gathered (cycles since creation of the instance) and write it to a file. Anyway, the usage looks like this:
void MyFunction()
{
#ifdef _DEBUG
CProfile* pProfile = new CProfile(__FILE__, __LINE__, "MyFunction"); // note the "MyFunction"
#endif
// rest of function
#ifdef _DEBUG
delete pProfile;
#endif
}
I''ve been searching for a macro that will give the string name of the current function, so I don''t have to manually write out the string for each different usage.
Also, I''ve always been confused about variable allocation to the stack/heap/etc. If I declare a pointer to a class, as I did, will it automatically be deleted at the end of the func? If not, is there a way I can declare the var so that it will be destroyed when it goes out of scope? Also, is this bad style, and I should delete it explicitly no matter what?
Thanx in advance.
