1

I'd like to make use of Electric Fence in an MFC application. I'd like to track new/ delete, and if I can track malloc/ free that's an added bonus.

Unfortunately, MFC redefines new and delete - but using macros (DEBUG_NEW) - so I can't use the standard C++ method of redefining them. (MFC defines them to have different signatures, with source file and line numbers as additional parameters).

Is there any way to force all new/ deletes to go via my allocator, and stop MFC trying to grab these allocators?

Unihedron
  • 10,902
  • 13
  • 62
  • 72
stusmith
  • 14,003
  • 7
  • 56
  • 89
  • Why can't you define your own DEBUG_NEW macro and use it instead of MFCs? – John Knoeller Feb 04 '10 at 09:14
  • It seems no matter how hard I try to get all the macros, there is still code in the bowels of MFC that will try to use the debug allocator. – stusmith Feb 04 '10 at 11:24
  • Unfortunately, the project I'm on takes approx. 30 mins to compile, so each little tweak to the main headers wastes a large part of my day. I'll try some more changes tonight and leave it building overnight. – stusmith Feb 04 '10 at 11:25

1 Answers1

1

You can stop the MFC hooking of new by redefining DEBUG_NEW in the end of stdafx.h

#undef DEBUG_NEW
#define DEBUG_NEW new
Arve
  • 7,284
  • 5
  • 37
  • 41
  • Unfortunately I've tried that - I couldn't seem to eliminate all of them. Some of them seem to be controlled by _AFX_NO_DEBUG_CRT, which it isn't possible to change. I've found that some always seem to slip through. – stusmith Feb 04 '10 at 10:10
  • Marking as correct answer as I think the problem I'm having is specific to our app. – stusmith Feb 11 '10 at 14:30