开发者

Exception in Memset

When try to do a memset it gives the following exception

"Unhandled exception at 0x1023af7d (PxSmartInterface.dll) in SendOutDllTestExe.exe: 0xC0000005: Access violation writing location 0x40e3a80e."

My memset statement will look like this

memset(lpStatus, 0, 开发者_高级运维csStatus.GetLength());


This is not a C++ exception, it's an operating exception. Either you accessed memory that didn't exist or you corrupted a data structure and crashed its destructor. (I'm assuming you're trying to zero out a block before deleteing the structure it contains.)

In C++ you don't typically call memset. std::fill does the same thing (and typically calls through to memset if possible), but with type safety.

If you want to zero out blocks of memory before freeing them, you need a debugging library. There's no clean way to access an object's memory after its destructor has been called and before free is called. Debug malloc is probably a feature of your dev environment.

Edit: you might be able to access pre-free memory for objects, but not arrays, by overriding delete. But that is NOT an activity for a beginner/intermediate.


Most likely, lpStatus does not point to csStatus.GetLength() bytes of writable memory. You need to examine the logic of how lpStatus is set.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜