Memset 中的异常

发布于 2024-08-25 16:59:30 字数 214 浏览 9 评论 0原文

当尝试执行 memset 时,会出现以下异常

“SendOutDllTestExe.exe 中 0x1023af7d (PxSmartInterface.dll) 处未处理的异常:0xC0000005:访问冲突写入位置 0x40e3a80e”。

我的 memset 语句将如下所示

memset(lpStatus, 0, csStatus.GetLength());

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());

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薆情海 2024-09-01 16:59:30

这不是 C++ 异常,而是操作异常。要么您访问了不存在的内存,要么损坏了数据结构并使其析构函数崩溃。 (我假设您在删除块包含的结构之前尝试将其清零。)

在C++中,您通常不会调用memsetstd::fill 执行相同的操作(如果可能的话,通常会调用 memset),但具有类型安全性。

如果您想在释放内存块之前将其清零,则需要一个调试库。在调用对象的析构函数之后和调用 free 之前,没有干净的方法来访问对象的内存。调试 malloc 可能是您的开发环境的一个功能。

编辑:您可以通过覆盖delete来访问对象的预空闲内存,但不能访问数组。但这不是适合初学者/中级的活动。

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.

寂寞笑我太脆弱 2024-09-01 16:59:30

最有可能的是,lpStatus 不指向可写内存的 csStatus.GetLength() 字节。您需要检查lpStatus 设置的逻辑。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文