是“#define new DEBUG_NEW”吗? 和“#undef THIS_FILE” 等等实际上有必要吗?
当您创建新的 MFC 应用程序时,向导会在几乎每个 CPP 文件中创建以下代码块:
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
有时它还会添加以下内容:
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
如果此代码是多余的,我想从我的 CPP 文件中删除此代码。 我在 VS2008 上使用带有 C++/CLI 的 MFC 应用程序。
从 CPP 中删除此代码后,我尝试在调试中运行,它似乎工作正常。 “new”变量工作正常,没有泄漏,并且 ASSERT 对话框显示正确的文件名并跳转到有问题的行。
谁能告诉我它的作用以及删除它是否安全?
When you create a new MFC application, the wizard creates the following block of code in almost every CPP file:
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
and sometimes it also adds this:
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
I would like to remove this code from my CPP files if it is redundant. I am using an MFC app with C++/CLI on VS2008.
I have tried running in Debug after deleting this code from a CPP, and it seems to work fine. "new"ing variables work fine, there are no leaks, and ASSERT dialogs show the correct filename and jump to the offending line.
Can anyone tell me what it does and whether it's safe to delete it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
删除它是完全安全的。 它是一种调试辅助工具; 保留它会在程序退出时出现的任何内存泄漏的输出窗口中的警告中生成更好的详细信息。 如果删除它,您仍然会收到内存泄漏报告,但只是没有有关源代码中发生位置的任何详细信息。
It is perfectly safe to delete this. It's a debugging aid; leaving it in will generate better details in the warnings in the output window of any memory leaks you have when the program exits. If you delete it, you still get the memory leak report, but just without any details about where in your source code they occurred.
在 Microsoft Visual C++ 2010 上,我可以删除整个代码并仅在标头中放入一个 #define NEW DEBUG_NEW,并且我仍然得到正确的内存泄漏报告,例如
On Microsoft Visual C++ 2010, I can remove the whole code and put just one #define NEW DEBUG_NEW in a header, and I still got the right memory leak reports, e.g.