我目前正在实施此处所述的泄漏检测:Finding Memory Leaks Using the CRT Library
使用以下宏,我使用DEBUG_NEW重新定义new关键字,如文章中所述:
#ifndef DBG_NEW
#define DBG_NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ )
#define new DBG_NEW
#endif
现在我在项目中使用了很多DirectX代码,并且当前没有编译new
。在创建D3DXMATRIXA16
:
m_pBoneMatrices = new D3DXMATRIXA16[m_maxBones];
这是抛出的编译器错误:
错误C2660:'_ D3DXMATRIXA16 :: operator new []':函数不带4个参数
我转到了_D3DXMATRIXA16
的定义,并在d3dx9math.h
中找到了这个:
#if _MSC_VER >= 1300 // VC7
#define D3DX_ALIGN16 __declspec(align(16))
#else
#define D3DX_ALIGN16 // Earlier compiler may not understand this, do nothing.
#endif
typedef struct _D3DXMATRIXA16 : public D3DXMATRIX
{
_D3DXMATRIXA16() {}
_D3DXMATRIXA16( CONST FLOAT * );
_D3DXMATRIXA16( CONST D3DMATRIX& );
_D3DXMATRIXA16( CONST D3DXFLOAT16 * );
_D3DXMATRIXA16( FLOAT _11, FLOAT _12, FLOAT _13, FLOAT _14,
FLOAT _21, FLOAT _22, FLOAT _23, FLOAT _24,
FLOAT _31, FLOAT _32, FLOAT _33, FLOAT _34,
FLOAT _41, FLOAT _42, FLOAT _43, FLOAT _44 );
// new operators
void* operator new ( size_t );
void* operator new[] ( size_t );
// delete operators
void operator delete ( void* ); // These are NOT virtual; Do not
void operator delete[] ( void* ); // cast to D3DXMATRIX and delete.
// assignment operators
_D3DXMATRIXA16& operator = ( CONST D3DXMATRIX& );
} _D3DXMATRIXA16;
typedef D3DX_ALIGN16 _D3DXMATRIXA16 D3DXMATRIXA16, *LPD3DXMATRIXA16;
编译器是VS2013,因此D3DX_ALIGN16定义为__declspec(align(16))
现在删除new
的定义显然会解决这个问题,但如果我怀疑此代码周围存在内存泄漏,有什么意义呢?
我不确定这里发生了什么。有没有办法绕过这个问题?我仍然希望能够在这里调试分配。