威尔的Visual C ++运行时的malloc /免费退换货内存操作系统? [英] Will Visual C++ runtime malloc / free return memory to OS?

查看:102
本文介绍了威尔的Visual C ++运行时的malloc /免费退换货内存操作系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的问题是类似<一个不少href=\"http://stackoverflow.com/questions/2215259/will-malloc-implementations-return-free-ed-memory-back-to-the-system\">Will malloc实现返回免费版内存回系统?,但我有兴趣了解一个答案为Windows /微软的Visual Studio,以及有关的确切虚拟内存状态的详细信息。

The question is a lot similar to Will malloc implementations return free-ed memory back to the system?, but I am interested about an answer for Windows / Microsoft Visual Studio, and about details on the exact virtual memory state.

威尔的Visual C ++ CRT 免费返回内存回系统?这将是相对于虚拟内存分配内存的确切状态?一个大的内存块做免费之后,将在该块内存被提交,保留或免费的吗?如果我叫 _heapmin 免费后?

Will Visual C++ CRT free return the memory back to the system? What will be the exact state of the memory in respect to virtual memory allocations? After doing free on a large memory block, will the memory in the block be committed, reserved, or free? What if I call _heapmin after the free?

推荐答案

检查源$ C ​​$ C于2010年,可以看到的malloc /免费电话的 HeapAlloc /的 HeapFree 直接Win32 API函数,以_crtheap由运行时创建一个堆。因此,对VS 2010和最近的Windows版本(WIN2000,WINXP,Vista中,WIN 7)答案是:

Inspecting the source code for 2010, it can be seen malloc/free call HeapAlloc/HeapFree Win32 API functions directly, with a _crtheap as a heap created by the runtime. The answer for VS 2010 and recent Windows versions (Win2000, WinXP, Vista, Win 7) therefore is:

由自由返回的内存被返回给操作系统,但它保持承诺。

堆函数文档说以下有关内存的承诺是如何处理的:

Heap Functions documentation says following regarding how is the memory commitment handled:

该HeapCreate函数创建一个私有堆对象从中调用进程可以用HeapAlloc函数来分配内存块。 ...附加页面会自动从该预留空间承诺如果HeapAlloc请求超过致力于页面的电流大小,假设它的物理存储是可用的。一旦页面承诺,他们没有或decommitted直到该进程被终止,直到堆是通过调用函数HeapDestroy销毁。

The HeapCreate function creates a private heap object from which the calling process can allocate memory blocks by using the HeapAlloc function. ... Additional pages are automatically committed from this reserved space if requests by HeapAlloc exceed the current size of committed pages, assuming that the physical storage for it is available. Once the pages are committed, they are not decommitted until the process is terminated or until the heap is destroyed by calling the HeapDestroy function.

此外 HeapCreate文档说以下有关堆的,没有最大尺寸设定的情况:

Moreover HeapCreate documentation says following regarding the case of a heap with no maximum size set:

如果dwMaximumSize是0,堆的尺寸增加。堆的大小只受可用内存的限制。请求分配比固定大小的堆不会自动失败的限制更大的存储器模块;代替,系统调用VirtualAlloc函数,以获得所需要的大的块的存储器。需要分配大的内存块应该设置dwMaximumSize为0的应用程序。

If dwMaximumSize is 0, the heap can grow in size. The heap's size is limited only by the available memory. Requests to allocate memory blocks larger than the limit for a fixed-size heap do not automatically fail; instead, the system calls the VirtualAlloc function to obtain the memory that is needed for large blocks. Applications that need to allocate large memory blocks should set dwMaximumSize to 0.

我没有发现任何可能说,这些数据块是否使用VirtualAlloc的在发布,可能会需要一个实验要知道这时候一种特殊的方式来处理分配。

I did not find anything which would say whether those block allocated using VirtualAlloc are handled in a special way when released, an experiment would probably be needed to know this.

至于 _heapmin ,用VS 2010是什么也不做,因为它仅调用 HeapCompact 和CRT堆不具备自动聚结自由关闭。因此,对_heapmin的文件似乎是错误的,最有可能的遗物从一些旧版本的运行时。

As for _heapmin, with VS 2010 is does nothing, as it only calls HeapCompact and the CRT heap does not have automatic coalesce on free turned off. The documentation for _heapmin therefore seems wrong, most likely a relic from some old version of the runtime.

这篇关于威尔的Visual C ++运行时的malloc /免费退换货内存操作系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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