Is it possible to replace the memory allocator in the debug build of an MFC application?

I would like to use Electric Fence in an MFC application. I would like to track new / delete , and if I can track malloc / free , then the added bonus.

Unfortunately, MFC overrides new and delete - but uses macros (DEBUG_NEW) - so I cannot use the standard C ++ method to override them. (MFC defines them to have different signatures, with source files and line numbers as additional parameters).

Is there a way to get all new / delete to go through my allocator and stop MFC trying to capture these allocators?

+1
source share
1 answer

You can stop switching MFC new by overriding DEBUG_NEW at the end of stdafx.h

 #undef DEBUG_NEW #define DEBUG_NEW new 
+1
source

Source: https://habr.com/ru/post/914683/


All Articles