I just discovered a nifty feature of MSVC++ 5 : The runtime debug library.
Other users out there may or may not know of this suite of tools (I just found
it myself after digging the MSDN CD out of a moving box)... so I figured I'd
share some info with any other needy coders out there :)
** NOTE ** The use I mention here is only one of many wonderful features of
the crtdbg lib... check out the docs included on the CDs for more.
== A Quick Way to Check for Memory Leaks (very basic overview :) ==
(I just threw all this in comm.c (include above main(), code inside just to
show that it works))
1. Make sure "/MLd" is set as a linker option -- automatically puts it in
debug mode. (note: other switches are used for other project types.. i.e.
multithreaded ones-- check the docs)
2. #include <crtdbg.h>
3. Stick this somewhere to see how it works, then test it out.
// ***** DEBUG *****
{short int *testthing = (short int *)malloc(8); // A malloc with no free?
Gasp!
testthing[0] = 0xF08; // Simple test values
testthing[1] = 0xCAF;
testthing[2] = 0x4CC;
testthing[3] = 0xEBB;}
_CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );
_CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDOUT );
_CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDOUT );
// Get current flag
int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
// Set only leak-checking bit
tmpFlag = _CRTDBG_LEAK_CHECK_DF;
// Set flag to the new value
_CrtSetDbgFlag( tmpFlag );
// ***** DEBUG *****
4. Build it, and execute (best if from within Dev Environ -- the red "!"
button)
You'll see an error report of the memory that was allocated but not freed :)
As long as the LEAK_CHECK bit is set, you'll see a report of any non-freed
memory at the program's shutdown. Check docs for other bits and uses (for
intense debugging :)
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
slightly more ObCircle...
If 3.0 was intended to have some form of OLC built in, why not just toss in
the GenOLC funcs from Oasis 2 (when finished) and let the coder decide from
there? (Just a suggestion).
+------------------------------------------------------------+
| Ensure that you have read the CircleMUD Mailing List FAQ: |
| http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
+------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/15/00 PST