|
|
Dmalloc Tutorial: 3.6 How to Disable the library
3.6 How to Disable the library
If you would like to disable the library's detailed checking features
during a particularly allocation intensive section of code, you can do
something like the following:
| | unsigned int dmalloc_flags;
…
/* turn off all debug flags and save a copy of old value */
dmalloc_flags = dmalloc_debug(0);
/* section of a lot of allocations */
…
/* end of section */
/* restore the dmalloc flag setting */
dmalloc_debug(dmalloc_flags);
|
When you are finished with the development and debugging sessions, you
may want to disable the dmalloc library and put in its place either the
system's memory-allocation routines, gnu-malloc, or maybe your own.
Attempts have been made to make this a reasonably painless process. The
ease of the extraction depends heavily on how many of the library's
features your made use of during your coding.
Reasonable suggestions are welcome as to how to improve this process
while maintaining the effectiveness of the debugging.
-
If you want to totally disable the dmalloc library then you will
need to recompile all the C files that include `dmalloc.h' while
defining
DMALLOC_DISABLE. This will cause the dmalloc macros to
not be applied. See section Macros Providing File and Line Information.
| | cc -g -DDMALLOC_DISABLE main.c
|
An alternative is to surround the dmalloc.h inclusion or any
direct dmalloc references with an #ifdef DMALLOC and then just
remove the -DDMALLOC.
| | #ifdef DMALLOC
#include "dmalloc.h"
#endif
main()
{
…
#ifdef DMALLOC
dmalloc_verify(0L);
#endif
return 0;
}
|
| | // to get dmalloc information
$ cc -Ddmalloc main.c
// without dmalloc information
$ cc main.c
|
-
If you compiled any of your source modules with
DMALLOC_FUNC_CHECK
defined then you must first recompile all those modules without the flag
enabled.
If you have disabled dmalloc with the DMALLOC_DISABLED flag or
never included `dmalloc.h' in any of your C files, then you will
not need to recompile your sources when you need to disable the library.
If you get unresolved references like _dmalloc_malloc or
_dmalloc_bcopy then something was not disabled as it should have
been.
This document was generated by Gray Watson on May, 16 2007 using texi2html 1.76.
This work is licensed by Gray Watson
under the Creative Commons
Attribution-Share Alike 3.0 License.
This page should be W3C Valid
XHTML and should work with most browsers.
|