Heap fragmentation is a state in which available memory is broken into small, noncontiguous blocks. When a heap is fragmented, memory allocation can fail even when the total available memory in the heap is enough to satisfy a request, because no single block of memory is large enough. The low-fragmentation heap (LFH) helps to reduce heap fragmentation.
堆碎片是一种状态,在这种状态,可用内存被分割成小的、不连续的块。当一个堆被碎片化后,内存分配会失败,即使总的可用内存是足够满足请求的,但单个块内存却不足够大。LFH可以帮助减少堆碎片。
The LFH is not a separate heap. Instead, it is a policy that applications can enable for their heaps. When the LFH is enabled, the system allocates memory in certain predetermined sizes. When an application requests a memory allocation from a heap that has the LFH enabled, the system allocates the smallest block of memory that is large enough to contain the requested size. The system does not use the LFH for allocations larger than 16 KB, whether or not the LFH is enabled.
LFH是应用可以采用的一种对堆使用的策略。当LFH被打开时,系统会用某种预估的size来分配内存。当应用从堆中请求内存时,系统会分配内存中比请求块大的最小的块。如果分配的size超过16KB,无论LFH打开与否都不会使用LFH。
An application should enable the LFH only for the default heap of the calling process or for private heaps that the application has created. To enable the LFH for a heap, use the GetProcessHeap function to obtain a handle to the default heap of the calling process, or use the handle to a private heap created by the HeapCreate function. Then call the HeapSetInformation function with the handle.
应用应该只对调用进程的默认堆和应用程序创建的private堆打开这个选项。
The LFH cannot be enabled for heaps created with HEAP_NO_SERIALIZE or for heaps created with a fixed size. The LFH also cannot be enabled if you are using the heap debugging tools in Debugging Tools for Windows or Microsoft Application Verifier.
对使用HEAP_NO_SERIALIZE 创建的堆或者对固定大小的堆不能打开LFH选项。如果你在使用heap debugging tools in windbg 或者Appverifier,LFH也是不能打开的。
After the LFH has been enabled for a heap, it cannot be disabled.
一旦LFH被打开,就不能被关闭。
Applications that benefit most from the LFH are multi-threaded applications that allocate memory frequently and use a variety of allocation sizes under 16 KB. However, not all applications benefit from the LFH. To assess the effects of enabling the LFH in your application, use performance profiling data.
对于那些经常分配内存、并且分配大小小于16K的多线程程序而言,LFH是很有用的。但是,不是所有的应用都可以从LFH中获益。