Dave's Brain

Browse - programming tips - win32 enable disable low fragmentation heap

Date: 2010apr30
OS: Windows

Q.  How do I enable the Low Fragmentation Heap (LFH) policy for the main heap?

A.  Use _get_heap_handle() to get the heap handle then call HeapSetInformation().
You could use this to turn off the LFN if it doesn't suit your application.

Here's an example from MSDN:

// crt_get_heap_handle.cpp
// compile with: /MT
#include <windows.h>
#include <malloc.h>
#include <stdio.h>

int main(void)
{
    intptr_t hCrtHeap = _get_heap_handle();
    ULONG ulEnableLFH = 2;
    if (HeapSetInformation((PVOID)hCrtHeap,
                           HeapCompatibilityInformation,
                           &ulEnableLFH, sizeof(ulEnableLFH)))
        puts("Enabling Low Fragmentation Heap succeeded");
    else
        puts("Enabling Low Fragmentation Heap failed");
    return 0;
}
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.