以后使用时,有效地址突然导致访问冲突0xC0000005 [英] Valid address suddenly causes Access Violation 0xC0000005 when used later

查看:104
本文介绍了以后使用时,有效地址突然导致访问冲突0xC0000005的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先让我尝试避免出现明显的情况.我没有NULL指针.  我没有一个指向错误地址的指针-至少一开始没有.

First let me try to avoid the obvious.  I do not have a NULL pointer.  I do not have a pointer pointing to a bad address - at least not at first.

第二,这是我看到的问题:我创建一个对象,但不删除该对象,访问该对象一段时间后会导致访问冲突.

Second, here is the problem I see: I create an object, I do not delete the object, after a while accessing the object causes an Access Violation.

我的猜测是,堆在某种程度上已被破坏,并且在某个时候,系统被告知不再使用我的对象分配所在的内存块的任何部分,而分配所在的内存块了,从我的身上被释放了 应用程序.

My guess is that the heap is somehow being corrupted, and at some point the system is being told that no part of the chunk of memory my objects allocation is in is being used anymore and the block of memory the allocation was in, became released from my application.

我的逻辑是,如果内存只是被破坏了,或者分配只是被释放了,那么我仍然可以访问它而不会引起访问冲突.是的,在这两种情况下,数据很可能是错误的,但不会导致访问 违反.

My logic is, if the memory were simply corrupted or if the allocation was simply free'd, then I could still access it without causing an Access Violation.  Yes the data could very likely be wrong in either of these cases, but it wouldn't cause an Access Violation.

注1:我几乎总是在同一位置得到错误(大约占我程序运行的80%).

Note 1: I almost always get the error in the same place (about 80% of runs of my program).

注2:我的程序是非常多线程的.

Note 2: My program is very heavily multi-threaded.

注3:不,我没有编写代码的这一部分,而是继承了它.

Note 3: No, I didn't code this part of it, I inherited it.

注4:该程序在装有Visual Studio 2005的计算机上,并且正在发布"模式下进行编译.我无法在系统上自由安装其他程序,并且我怀疑是否可以安装诸如边界检查器之类的工具(我相信它被称为开发合作伙伴 现在).

Note 4: The program is on a machine with Visual Studio 2005, and it is being compiled in Release mode.  I cannot freely install further programs on the system, and I doubt I can install a tool like bounds checker (I believed it is named dev partner now).

注释5:很难始终如一地重现此问题,因此我可能必须在Release模式下对其进行调试,而无需任何类型的调试堆.

Note 5: This problem was very difficult to reproduce consistently, so I will probably have to debug it in Release mode, without any sort of debug heap.

这是我尝试确定何时内存不可用的方法:

Here is how I tried to determine when the memory becomes unavailable:

A)访问我分配一次且永不释放的对象的布尔字段时发生错误.

A) The error happens when accessing a bool field of an object I allocate once and never free.

B)分配对象时,将指向布尔的指针存储在全局变量中.

B) When I allocate the object I store a pointer to the bool in a global variable.

C)我通过它的指针在整个程序中的许多不同线程中散布了该布尔的用法.

C) I sprinkle usages of that bool, via its pointer, throughout my program, in many different threads.

D)我注意到代码中开始出现访问冲突,并添加了更多访问该bool的调用,以查看当无效时是否可以缩小范围.我还在程序暂停时停止使用的其他线程中散布了布尔值 在访问冲突中.

D) I note were in the code I start getting Access Violations and add more calls to access that bool, to see if I can narrow down when it becomes invalid.  I also sprinkle uses of that bool in other threads that are stopped when my program is halted at the Access Violation.

我发现大多数访问冲突都发生在相同的代码区域中,但是我不知道为什么.

I found that most of the Access Violations happen in the same few areas of code, but I couldn't figure out why.

 

我正在寻找一种可以告诉我何时内存块停止对我有效的方式.是否可以查询某种内存管理器,以查看哪些内存块对我的程序有效?记住我有一个有效的指针 在分配它的时候,也许我可以监视它所在的块何时返回系统.

What I am looking for is a way that I can tell when the block of memory stops being valid for me to use.  Is there some sort of memory manager that I can query to see what blocks of memory are valid for my program?  Remember I have a valid pointer at the time I allocate it, perhaps I can monitor when the block it is in gets returned to the system.

对于可能出现的问题以及如何解决该问题,我持开放态度.

I am open to other ideas of what the problem can be and how to fix it.

但是我的时间很短,程序很复杂,没有时间改进其体系结构,所以我确实需要找出发生这种情况的原因.  我可以确定自己已修复的唯一方法是,如果我确定其来源-我不能只是更改 在代码运行的方式上,这样就可以神奇地停止问题的发生,更改线程数或延迟它们并使其消失似乎是很容易的,但是在那些情况下,我确信问题会再次困扰我.我已经花了 个星期试图在许多系统上重现此问题,我终于找到了一种在一台机器上一致地重现此问题的方法.

BUT I am short on time, the program is complex, and there is no time to improve its architecture, so I really do need to track down why this is happening.  The only way I can be sure I have fixed it, is if I determine its source - I cannot just change the way the code runs so that the problem magically stops happening, it is fairly easy to change how many threads or delay them and have the problem appear to go away, but in those cases I am sure the problem will come back to haunt me.  I have spent weeks trying to reproduce this problem on many systems, and I have finally found one way to reproduce it consistently on one machine.

感谢您提供的任何帮助,

Thank You for any help you can provide,

John Petritis

John Petritis

P.S.对这么长的时间感到抱歉,但是我不想浪费你的时间或我的时间.

P.S. Sorry about being so long winded, but I don't want to waste you time or mine.

P.P.S.请注意,我没有发布任何代码示例,因为我不相信它们可以提供帮助,它是一个简单的对象,其中许多字段之一是布尔值.我正在32位Windows XP上运行它,并且我正在使用Visual Studio 2005,该程序是

P.P.S. Note that I did not post any code samples because I don't believe they could help, it is a simple object, in which one of its many fields is a bool.  I am running it on Windows XP 32 bit, and I am using Visual Studio 2005, and the program is in c++.

推荐答案

约翰,

问题仅在发布模式下发生?在调试模式下是否有任何AV?

请注意在调试模式下,所有未初始化的变量会自动初始化为调试建议的特殊值.但是在发布中 模式下,这些未初始化的变量将被分配任何可能的值,该值取决于当时的内存位置值.初始化的变量可能指向导致访问冲突的某个位置.这可能是一个可能的原因 为您的问题.我建议您调试代码,检查调用堆栈以查找导致AV的变量,然后再次检查此变量是否正确初始化.

Please note that in debug mode all uninitialized variables are initialized automatically to a special value for debug propose. However in release mode, these uninitialized variables will be assigned with anything possible value which depends on the value of the location of memory at the time. The initialized variable may point to some place which leads Access Violation. This could be one possible cause for your problem. I suggest you debug your code, check the call stack to find which variable leads the AV and double check whether this one is initialized properly.

致谢,
易风丽
论坛中的MSDN订阅者支持
如果您对我们的支持有任何反馈意见,请联系
msdnmg@microsoft.com .

Regards,
Yi Feng Li
MSDN Subscriber Support in Forum
If you have any feedback of our support, please contact
msdnmg@microsoft.com.


这篇关于以后使用时,有效地址突然导致访问冲突0xC0000005的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆