Reputation: 3299
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());
Upvotes: 1
Views: 3678
Reputation: 76531
Most likely, lpStatus
does not point to csStatus.GetLength()
bytes of writable memory. You need to examine the logic of how lpStatus
is set.
Upvotes: 1
Reputation: 137790
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 delete
ing 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 free
ing 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.
Upvotes: 2