VS2010 _DELETE_CRT macro in STL
VS2010 _DELETE_CRT macro in STL
如何在VS2010的STL实现中关闭"对调试堆的支持"?我写了一个内存跟踪器,它重载new和delete,并在分配之前添加一个跟踪节点。遗憾的是,一些STL对象使用了我的运算符new,然后尝试用下面的宏删除,而不是我的运算符delete。这意味着他们试图free
一个malloc
没有返回的地址。由于下面的宏,我的代码在调试时崩溃了,但在发布时没有崩溃(哈哈)。
来自<xdebug>
:
// SUPPORT FOR DEBUG HEAP
#if defined(_DEBUG)
#define _DELETE_CRT(ptr) _STD _DebugHeapDelete(ptr)
template<class _Ty>
void __CLRCALL_OR_CDECL _DebugHeapDelete(_Ty *_Ptr)
{ // delete from the debug CRT heap even if operator delete exists
if (_Ptr != 0)
{ // worth deleting
_Ptr->~_Ty();
// delete as _NORMAL_BLOCK, not _CRT_BLOCK, since we might have
// facets allocated by normal new.
free(_Ptr);
}
}
#else /* defined(_DEBUG) */
#define _DELETE_CRT(ptr) delete (ptr)
作为参考,确切的崩溃在locale operator=
:中
locale& operator=(const locale& _Right) _THROW0()
{ // assign a locale
if (_Ptr != _Right._Ptr)
{ // different implementation, point at new one
_DELETE_CRT(_Ptr->_Decref());
_Ptr = _Right._Ptr;
_Ptr->_Incref();
}
return (*this);
}
我甚至看不出_DebugHeapDelete
在买什么——它看起来和operator delete
在任何配置中都会做的一样。
在您的环境中设置_NO_DEBUG_HEAP=1
。
(顺便说一句,这是一个环境变量,而不是#define
)
相关文章:
- netcat command in c++
- 在C++STL中是否有Polyval(Matlab函数)等价物?
- Difference in displaying cv2 Mat
- 为什么这个运算符<重载函数对 STL 算法不可见?
- 在C应用程序中运行C++(带有STL)函数
- 使用2个键的cpp-stl::优先级队列排序不正确
- C++ MFC Libraries in Travis CI
- 如何在OpenSSL中从configuration.h.in获取configuration.h
- 在STL容器中使用模板类
- 用C++中的CPerson(类)类型的对象初始化STL矢量
- find() stl in vector in c++
- C++ map::find() in stl
- QStringList alternative in STL or Boost
- The priority_queue of STL in c++
- 哪个 STL 类用于 Rand-In-First-Out-Buffer
- VS2010 _DELETE_CRT macro in STL
- "Cannot evaluate function -- may be in-lined" STL 模板容器的 GDB 错误
- boost::scoped_ptr and STL in C++
- STL & Overload in C++
- Android NDK STL c++_shared w/LIBCXX_FORCE_REBUILD results in