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

北慕城南 提交于 2019-12-11 07:24:45

问题


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:


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


来源:https://stackoverflow.com/questions/2198401/is-it-possible-to-replace-the-memory-allocator-in-a-debug-build-of-an-mfc-applic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!