1

I wish to create a build of a project constructed so that it is identical to the release build, except that the debug version of the default allocator is used (with canary checks on alloc/free and so on). The compiler/CRT is Visual Studio 2010.

Reading the documentation for the CRT it seems that _DEBUG needs to be defined for calls to _CrtCheckMemory(), _malloc_dbg(), etc. to not be removed. I do not wish to enable the _DEBUG define since this will influence more than the allocator.

Is there a way to use the CRT debug allocator without having _DEBUG defined?

Viktor
  • 3,295
  • 2
  • 25
  • 26

2 Answers2

1

_malloc_dbg() requires the debug runtime, the debug runtime requires _DEBUG - So no, you can't do this.

Erik
  • 88,732
  • 13
  • 198
  • 189
  • Ok. So its either _DEBUG (maybe with optimization enabled) or rolling my own heap check... – Viktor Mar 18 '11 at 12:06
  • @Viktor: Yup, or use some external tool - see e.g. http://stackoverflow.com/questions/413477/is-there-a-good-valgrind-substitute-for-windows – Erik Mar 18 '11 at 12:09
0

You could find out the name of the malloc call that is used when _DEBUG is defined, and manually define malloc to use that instead?

Same with new if you're using c++, you could create a global override to the debug version

deek0146
  • 962
  • 6
  • 20
  • Won't work. As stated, `_malloc_dbg` is a part of the debug runtime - using the debug runtime without defining `_DEBUG` will break. – Erik Mar 18 '11 at 10:34