Dmalloc Logo


Search this site:

If dmalloc has saved you or your company time or money, please use your credit-card or PayPal account to donate to the cause.

Dmalloc Tutorial: 3.7 How to Disable the library
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.7 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 */

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 file.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"
    #ifdef DMALLOC
      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.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]

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.