unique_ptr 删除程序导致我的程序崩溃
在运行时,当我关闭程序时,我收到错误:“crt 检测到应用程序在堆缓冲区结束后写入内存。”我通过析构函数跟踪程序执行到唯一 ptr 的删除器,并且在调用删除器函数时发生错误。我想提到的另一个问题是,由于某种原因,唯一 ptr 所在的类定义要求它有一个公共复制构造函数。我尝试在另一个具有不同类和相同类的项目中复制这些问题,删除复制构造函数和析构函数并更改访问标签。我无法复制相同的问题 - 这两个项目之间最大的区别是有问题的一个是共享库,这可能是问题所在吗?必须定义复制构造函数,虽然烦人且多余,但我并不太关心,任何有关此内存错误的猜测或建议都将受到高度赞赏。
At run time when I close my program I get the error: "crt detected that the application wrote to memory after end of heap buffer." I followed the program execution through a destructor to the deleter of the unique ptr and the error occured on the call to the deleter function. Another problem I want to mention is that for some reason the class defenition that the unique ptr is in requires that it has a public copy constructor. I tried to replicate these problems in another project with a different class and the same one, removing the copy constructor and destructor and changing the access labes. I couldn't replicate the same problems - the biggest difference between these two projects is the one with problems is a shared library, could this be the problem? Having to define the copy constructor although annoying and redundant I dont really care to much about, any speculations or advice on this memory error would be highly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,当您调用删除时,会出现此消息,但它表示发现一个错误。没有造成一。在代码中的某个位置,您正在写入超出数组末尾的内容,然后在删除过程中,内存管理器在越界区域中发现了“足迹”。
在每次访问数组之前,输入:
Yes, this message appears when you call delete, but it's saying it found an error. Not caused one. Somewhere in your code, you are writing past the end of an array, and then during the delete, the memory manager found "footprints" in an out-of-bounds area.
Before each and every array access, put in :