虚拟内存地址空间不足(Borland C ++ Builder 6程序) [英] Out of virtual memory address space (Borland C++ Builder 6 program)

查看:211
本文介绍了虚拟内存地址空间不足(Borland C ++ Builder 6程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用C ++ Builder 6编写的某些应用程序有问题.运行一段时间(一周,一个月)后,该应用程序崩溃并关闭,没有任何错误消息.在崩溃前不久的应用程序日志中,我遇到了许多内存不足"异常. 当它抛出内存不足异常时(在下面的截图中),它有很多未分配的私有内存空间,我查看了该过程.发生这种行为的原因可能是什么?

I have problem with some application written under C++ Builder 6. After some time of running (week, month) the application crashes and closes without any error message. In my application log shortly before crash i get many "Out of memory" exceptions. I looked at the process when it was throwing out of memory exceptions (screenshot below) and it has lots of uncommitted private memory space. What can be a reason of such behavior?

几年前,我曾经遇到过这样的问题.原因是在链接器选项中未选中使用动态库"选项.当我检查回来时,问题消失了,反之亦然.我创建的测试应用程序只是调用"new char [1000000]",然后删除.每次都释放内存(Windows任务管理器中没有承诺的内存增加),但是一段时间之后,我失去了内存,VMMap显示了完全相同的内容.许多保留的专用内存,但大多数未提交.

I had such problem once, couple years ago. The reason for that was an option "use dynamic libraries" unchecked in linker options. When I checked it back the problem disappeared and vice versa. The test application which I made was just calling "new char[1000000]" and then delete. The memory was freed every time (no committed memory rise in windows task manager), but after some time I got out of memory, VMMap showed exactly the same thing. Lots of reserved private memory but most of it uncommitted.

现在问题又回来了,但是我不能用同样的方式解决它.我不知道这是不是原因,但是我在同一台计算机上安装了Builder 6和2010.现在我只有Builder 6,看来我无法像以前一样用测试应用程序重现该错误.以太方式似乎存在一些内存管理器错误或某些错误. CodeGuard不显示任何内存泄漏.当我用"new"创建内存块时,它立即显示为"memory commit size",而删除时内存使用量减少了,因此我认为内存泄漏不是这种情况,任务管理器不会显示太多的"memory commit size"

Now the problem returned but I can't fix it the same way. I don't know if that was the reason but I had Builder 6 and 2010 istalled on the same machine. Now I just have Builder 6 and it seems that I cannot reproduce the error with test application like before. Ether way it seems that there is some memory manager error or something. CodeGuard doesn't show any memory leaks. When I create memory block with "new" it instantly shows in "memory commit size" and when delete the memory usage decreases, so I assume that the memory leaks are not the case, task manager doesn't show much "memory commit size".

有什么我可以做的吗?有什么办法可以释放未分配的内存?如何进一步诊断问题?

Is there anything I can do? Is there any way I can release uncommitted memory? How to diagnose the problem any further?

屏幕截图: http://i.stack.imgur.com/UKuTZ.jpg

推荐答案

我找到了一种模拟此问题和解决方案的方法.

I found a way to simulate this problem and solution.

for(int i=0; i<100; i++)
{
    char * b = new char[100000000];
    new char;
    delete b;
}

Borland内存管理器保留一块内存,该内存块的大小是一页的倍数,即4kB.当分配的内存大小不同于4kB的倍数时,存在一些可用空间,borland可以使用这些可用空间来分配其他一些内存块.当第一个块被释放后,第二个块仍保留空洞存储块.

Borland memory manager reserves a block of memory which size is multiple of one page which is 4kB. When allocating memory size different than multiple of 4kB there is some free space which borland may use to allocate some other memory chunk. When the first chunk is deallocated the second is still keeping hole memory block reserved.

乍一看,该代码仅会导致100B内存泄漏,但实际上,在少于16次迭代后,它将导致内存分配异常.

At first look the code should cause just 100B memory leak, but in fact it will cause memory allocation exception after less than 16 iterations.

我为此问题找到了两个解决方案.一种是FastMM,它可以工作,但也带来一些麻烦. 第二种解决方案是与Embarcadero Rad Studio 2010中的其中一个交换borlndmm.dll.我尚未对其进行全面测试,但它似乎可以正常工作.

I have found two solutions for this problem. One is FastMM, it works but also brings some troubles with it too. Second solution is to exchange borlndmm.dll with the one from Embarcadero Rad Studio 2010. I didn't test it thoroughly yet but it seems to work without any problem.

我应该将Hole项目移至RAD 2010,但由于某些原因,我被卡在Borland 6中.

I should move the hole project to RAD 2010 but for some reasons I got stuck in Borland 6.

这篇关于虚拟内存地址空间不足(Borland C ++ Builder 6程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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