The _CrtIsValidHeapPointer function is used to ensure that a specific memory address is within the local heap. The “local” heap refers to the heap created and managed by a particular instance of the C run-time library. If a dynamically linked library (DLL) contains a static link to the run-time library, then it has its own instance of the run-time heap, and therefore its own heap, independent of the application’s local heap. When _DEBUG is not defined, calls to _CrtIsValidHeapPointer are removed during preprocessing.Top
如上文所述(MSDN):
_CrtIsValidHeapPointer确认内存地址在本地堆。……如果静态链接C运行库,那么,dll拥有一个独立于应用程序(调用它的exe)的本地堆。(所以你上面的程序会Debug Assertion Failed),如果没有定义_DEBUG,那么_CrtIsValidHeapPointer将被预处理器移除。
所以方法有二:
1、动态链接C运行库。
2、设置为release版本。
Top
多谢各位!
to sinall:
我已经全部设为release版本, 直接执行程序, 但是程序提示:遇到问题需要关闭。我们对此引起的不便表示抱歉。
是不是可能是我修改的DLL程序有问题!Top
嗯,不好意思,release版本应该会跳过该句,不过,如果“Assertion Failed”的话,估计程序是会出问题的。
恐怕,你的使用方式有问题。
能否把调用代码和dll函数代码贴出来一看。
====================
what everybody said is close right. but the essential reason is about memory created and deleted. So after we allocate a new memory ,we should pay more attention to delete it correctly. we should promise to delete the same size of memory. Memcpy function is very dangerous, keep it is used in right way.
Copies characters between buffers.
void *memcpy( void *dest, const void *src, size_t count );
Character is key in copying period. if you force to transfer a class to string buffers and copy it to another position, you should guarantee buffer size is not changed.
in conclusion, we don't do it to avoid such assertions.
|