是否可以在MFC应用程序的调试版本中替换内存分配器? [英] Is it possible to replace the memory allocator in a debug build of an MFC application?
问题描述
我想在其中的电子围栏中使用MFC应用程序.我想跟踪new
/delete
,如果我可以跟踪malloc
/free
,那将是一个额外的奖励.
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.
不幸的是,MFC重新定义了new
和delete
-但是使用了宏(DEBUG_NEW)-因此我无法使用重新定义它们的标准C ++方法. (MFC将它们定义为具有不同的签名,并将源文件和行号作为附加参数).
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).
有没有办法强制所有new
/delete
通过我的分配器,并停止MFC尝试获取这些分配器?
Is there any way to force all new
/ delete
s to go via my allocator, and stop MFC trying to grab these allocators?
推荐答案
您可以通过在stdafx.h末尾重新定义DEBUG_NEW来停止MFC对new的钩住.
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
这篇关于是否可以在MFC应用程序的调试版本中替换内存分配器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!