是否可以在MFC应用程序的调试版本中替换内存分配器? [英] Is it possible to replace the memory allocator in a debug build of an MFC application?

查看:80
本文介绍了是否可以在MFC应用程序的调试版本中替换内存分配器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在其中的电子围栏中使用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重新定义了newdelete-但是使用了宏(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/ deletes 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆