Enables features for a specified heap.
BOOL HeapSetInformation( HANDLE HeapHandle, HEAP_INFORMATION_CLASS HeapInformationClass, PVOID HeapInformation, SIZE_T HeapInformationLength );
The class of information to be set. This parameter can be one of the following values from the HEAP_INFORMATION_CLASS enumeration type.
Enables heap features. Only the
low-fragmentation heap (LFH) is supported.
However, it is not necessary for applications to enable the LFH because the system uses the LFH as needed to
service memory allocation requests.
Windows XP and Windows Server 2003: The LFH is not enabled by default. To enable the LFH for the specified heap, set the variable pointed to by the HeapInformation parameter to 2. After the LFH is enabled for a heap, it cannot be disabled.
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.
When a process is run under any debugger, certain heap debug options are automatically enabled for all heaps in the process. These heap debug options prevent the use of the LFH. To enable the low-fragmentation heap when running under a debugger, set the _NO_DEBUG_HEAP environment variable to 1.
Enables the terminate-on-corruption feature. If the heap manager detects an error in any heap used by the
process, it calls the Windows Error Reporting service and terminates the process.
After a process enables this feature, it cannot be disabled.
Windows Server 2003 and Windows XP: This value is not supported until Windows Vista and Windows XP with SP3. The function succeeds but the HeapEnableTerminationOnCorruption value is ignored.
If HeapSetInformation is called with HeapHandle set to NULL, then all heaps in the process with a low-fragmentation heap (LFH) will have their caches optimized, and the memory will be decommitted if possible.
If a heap pointer is supplied in HeapHandle, then only that heap will be optimized.
Note that the HEAP_OPTIMIZE_RESOURCES_INFORMATION structure passed in HeapInformation must be properly initialized.
Note This value was added in Windows 8.1.
The heap information buffer. The format of this data depends on the value of the HeapInformationClass parameter.
If the HeapInformationClass parameter is HeapCompatibilityInformation, the HeapInformation parameter is a pointer to a ULONG variable.
If the HeapInformationClass parameter is HeapEnableTerminationOnCorruption, the HeapInformation parameter should be NULL and HeapInformationLength should be 0
The size of the HeapInformation buffer, in bytes.
If the function succeeds, the return value is nonzero.
If the function fails, the return value is 0 (zero). To get extended error information, call GetLastError.
To retrieve the current settings for the heap, use the HeapQueryInformation function.
Setting the HeapEnableTerminateOnCorruption option is strongly recommended because it reduces an application's exposure to security exploits that take advantage of a corrupted heap.
The following example shows you how to enable the low-fragmentation heap.
#include <windows.h> #include <tchar.h> #include <stdio.h>
|Minimum supported client||Windows XP [desktop apps | UWP apps]|
|Minimum supported server||Windows Server 2003 [desktop apps | UWP apps]|
|Header||heapapi.h (include Windows.h)|