It allows a user to replace code such as:
#if defined(_MSC_VER) && \ defined(_DEBUG) # include <crtdbg.h> #endif int main(int argc, char** argv) { #if defined(_MSC_VER) && \ defined(_DEBUG) _CrtMemState memState; _CrtMemCheckpoint(&memState); #endif int result; . . . // main program logic (which must assign to result) #if defined(_MSC_VER) && \ defined(_DEBUG) _CrtMemDumpAllObjectsSince(&memState); #endif return result; }
with:
#include <pantheios/extras/diagutil.hpp> int program(int argc, char** argv) { . . . // main program logic return EXIT_SUCCESS; } int main(int argc, char** argv) { return pantheios::extras::diagutil:: main_leak_trace::invoke(argc, argv, program); }
or, if your program is written in C, with:
#include <pantheios/extras/diagutil.h> int program(int argc, char** argv) { . . . // main program logic return EXIT_SUCCESS; } int main(int argc, char** argv) { return pantheios_extras_diagutil_main_leak_trace_invoke( argc, argv, program); }
The immediate advantate is clear: substantially improved transparency in your application code. There are three secondary advantages:
- you do not need to explicitly conditionally include crtdbg.h
- the library can be enhanced in the future to work with other compiler-extensions, without requiring any changes to your code
- you do not have to avoid the use of
return
statements in your main program logic, and to remember to assign toresult
More memory-tracing functionality will appear in forthcoming releases.
No comments:
Post a Comment