【问题标题】:Cannot compile with memory dump for some files无法编译某些文件的内存转储
【发布时间】:2011-04-05 15:46:04
【问题描述】:

我使用这个 Debug.h 文件作为我要调试内存泄漏的文件的最后一个#include。然后使用 _CrtDumpMemoryLeaks();将其转储到我的输出中。这对大多数文件都适用,但是当我将其包含在某些文件中时,会出现以下错误。看起来它与 boost::unorderer_map .. 但我可以将我的 Debug.h 包含到 .h 文件中,我在其中定义和使用 unordered_map 没有任何错误.. 当我得到错误时将它包含在我什至不使用它的 .h 文件中..

#ifndef DEBUG_H
#define DEBUG_H

#ifdef _DEBUG
#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
#define new DEBUG_NEW
#endif

#endif

1>d:\uni\ict312\labproject\labproject\inc\boost\unordered\detail\fwd.hpp(351):错误 C2059:语法错误:'(' 1> d:\uni\ict312\labproject\labproject\inc\boost\unordered\detail\fwd.hpp(350) : 在编译类模板成员函数'void boost::unordered_detail::hash_buffered_functions::construct(bool,const H &,常量 P &)' 1> 与 1> [ 1> H=升压::哈希, 1> P=std::equal_to 1>] 1> d:\uni\ict312\labproject\labproject\inc\boost\unordered\detail\fwd.hpp(432) : 参见正在编译的类模板实例化 'boost::unordered_detail::hash_buffered_functions' 的参考 1> 与 1> [ 1> H=升压::哈希, 1> P=std::equal_to 1>] 1> d:\uni\ict312\labproject\labproject\inc\boost\unordered\detail\fwd.hpp(572) : 请参阅正在编译的类模板实例化 'boost::unordered_detail::hash_table' 的参考 1> 与 1> [ 1> T=boost::unordered_detail::map,std::equal_to,std::allocator>> 1>] 1> d:\uni\ict312\labproject\labproject\inc\boost\unordered\unordered_map.hpp(98) : 请参阅正在编译的类模板实例化 'boost::unordered_detail::hash_unique_table' 的参考 1> 与 1> [ 1> T=boost::unordered_detail::map,std::equal_to,std::allocator>> 1>] 1> d:\uni\ict312\labproject\labproject\inc\collisiondetector.h(15) : 请参阅正在编译的类模板实例化 'boost::unordered_map' 的参考 1> 与 1> [ 1> K=无符号整数, 1> T=物理对象 1>]

【问题讨论】:

  • 也许我有些困惑,但据我所知,您在使用 _CrtDumpMemoryLeaks() 时不需要需要任何 DEBUG_NEW。您还想正确格式化错误消息!
  • Martin:_CrtDumpMemoryLeaks 在没有 DEBUG_NEW 的情况下工作,但它不显示文件名和行号,只显示内存地址。

标签: c++ visual-studio-2008 mfc boost memory-leaks


【解决方案1】:

您的意思是,您在所有其他 #include 行之后包含 Debug.h,并且仍然在 boost 标头中出现编译错误?当编译器尝试实例化模板类时,可能会发生这种情况,此时模板代码才真正被编译。防止这种情况的唯一方法是在导致此错误的代码片段中返回原始 new 运算符。没有机会用重新定义的 new 运算符编译 boost 的东西。

另一种方法是将未编译的代码行移动到单独的 .cpp 文件中,无需重新定义。

【讨论】:

    猜你喜欢
    • 2013-09-21
    • 2012-11-10
    • 2015-03-20
    • 2015-06-07
    • 1970-01-01
    • 1970-01-01
    • 2016-09-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多