views:

26

answers:

1

Background: 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?

+1  A: 

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
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
Marking as correct answer as I think the problem I'm having is specific to our app.
stusmith