Microsoft VC运行时堆碎片 [英] Microsoft VC Runtime Heap Fragmentation

查看:93
本文介绍了Microsoft VC运行时堆碎片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我有堆碎片问题。当我执行代码(见下文)时,Microsoft VC Runtime Heap如此多碎片(见下表),我无法创建大型对象。有没有办法清理堆?

I have problem with heap fragmentation. When I execute code (see below), Microsoft VC Runtime Heap so much fragmented (see table below), that I cannot create huge objects. Is exist any way to clean up the heap?

Native C ++ Project(32位),VS2010 Ultimate,Windows 7 64位企业

Native C++ Project (32-bit), VS2010 Ultimate, Windows 7 64-bit Enterprise

typedef struct

{

double mvChanVal [52];

double mvChanVal [52];

} TVal;

const int count = 10000;

const int count = 10000;

TVal * * pVectors = new TVal * [count];

TVal* *pVectors = new TVal* [count];

for(int i = 0; i< count; i ++)

for (int i= 0; i < count; i++)

{

TVal * pValue = new TVal [300] ;; pVectors [i] = pValue;

TVal* pValue = new TVal[300];; pVectors[i] = pValue;

}

for(int i = 0; i< count; i ++)

for (int i= 0; i < count; i++)

{

delete [] pVectors [i];

delete[] pVectors[i];

}

删除[] pVectors;

delete[] pVectors;


虚拟内存摘要


< table cellspacing ="3">


最大免费虚拟机数据块的大小
< td>    415.25 MBytes


可用内存碎片
   45.30%


免费记忆
   759.19 MBytes   (占总记忆的37.07%)


预留记忆
   1.21 GBytes   (60.65%of总内存)


承诺内存
   46.76 MBytes   (总内存的2.28%)


总内存
    2.00 GBytes


最大的免费区块在
   0x00000000`4d500000



Virtual Memory Summary

Size of largest free VM block   415.25 MBytes
Free memory fragmentation   45.30%
Free Memory   759.19 MBytes   (37.07% of Total Memory)
Reserved Memory   1.21 GBytes   (60.65% of Total Memory)
Committed Memory   46.76 MBytes   (2.28% of Total Memory)
Total Memory   2.00 GBytes
Largest free block at   0x00000000`4d500000

...约70个条目

推荐答案

定义巨大的对象。

Define huge objects.

对于您将能够创建的内存块的大小总会有一些限制。即使在64位版本的Windows上运行的32位进程中启用了大地址识别功能,这也不会为您提供整个4GB的地址空间,大约为
,这将为您提供大约3.5GB的空间。

There is always going to be some limit on the size of a memory block you are going to be able to create. Even with large address aware enabled in a 32 bit process running on a 64 bit version of Windows, this won't give you the entire 4GB address space, at most this will give you around 3.5GB.

由于加载了DLL,你的应用程序本身,并且你很可能在一个进程中找到至少两个堆,然后在不使用大地址识别的情况下分配超过1GB可能很困难。请记住,进程的虚拟地址空间不是刚刚被数据占用的
,所有代码也都在那里。哦,是的,还要记住,你使用的任何DLL也可能也需要分配内存,这一切都在这里。 Windows分配的任何内存都不会进入你的CRT堆,所以如果从Windows分配内存
,那么清理CRT堆将无济于事。

Because of DLLs loading in, your application itself, and you'll most likely find at least two heaps in a process normally then it may be hard to allocate more than 1GB without using large address aware. Remember, the virtual address space for a process isn't just taken up by data, all of the code goes in there too. Oh yea, also, remember that any DLLs that you use may also need to allocate memory too, this all goes in here. Any memory allocated by Windows will not go on your CRT heap, so if you get memory allocated from Windows, then cleaning up the CRT heap will not help.

如果你将在x64版本的Windows上独占运行此应用程序,在链接器选项中启用大地址识别将有所帮助,如果您需要更多内存,那么为x64构建它也会有所帮助。否则请查看内存映射的
文件。

If you are going to be running this application exclusively on an x64 version of Windows, enabling large address aware in the linker options will help, if you need more memory than that then building it for x64 will also help. Otherwise look at memory mapped files.


这篇关于Microsoft VC运行时堆碎片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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