原文链接 -> 传送门
函数功能:
HeapQueryInformation 函数用于获取指定堆的信息。
API 函数原型:
注释:_In_ 说明该参数是输入的,_Out_ 说明该参数是输出的,_opt_ 说明该参数是可选的。
BOOL WINAPI HeapQueryInformation( _In_opt_ HANDLE HeapHandle, _In_ HEAP_INFORMATION_CLASS HeapInformationClass, _Out_ PVOID HeapInformation, _In_ SIZE_T HeapInformationLength, _Out_opt_ PSIZE_T ReturnLength );
参数解析:
|
参数 |
含义 |
||||
|
HeapHandle |
1. 指向待获取信息的堆句柄 |
||||
|
HeapInformationClass |
1. 指定待获取的堆信息
|
||||
|
HeapInformation |
1. 指向堆信息缓冲区指针 |
||||
|
HeapInformationLength |
指定被查询的堆信息长度,单位字节 |
||||
|
ReturnLength |
1. 指向接收被写入到 HeapInformation 指向的缓冲区的数据长度指针。如果缓冲区太小,函数调用失败且 ReturnLength 为需要的缓冲区最小值 |
返回值:
1. 如果函数调用成功,返回值是非 0;
2. 如果函数调用失败,返回值是 0。
若想获得更多的错误信息,请调用 GetLastError 函数。
备注:
1. 使用 HeapSetInformation 函数启用低碎片堆或堆溢出终止功能特性。
2. Windows XP and Windows Server 2003:
后备链表是一个快速的内存分配机制,但只适用于固定大小的内存块。如果堆支持后备链表,则默认启用。从 Windows Vista 开始,后备链表不使用,低碎片堆默认启用。
后备链表比通用池不同大小的内存分配速度快,因为系统不搜索适合分配的空闲内存。此外,访问后备链表通常使用快速原子处理器交换指令同步,而非互斥或自旋锁。后备链表可以由系统或驱动程序创建。可以从分页池或者未分页池分配。
例子:
下例是使用 GetProcessHeap 函数获取默认进程堆句柄和使用 HeapQueryInformation 函数获取堆信息。
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#define HEAP_STANDARD 0
#define HEAP_LAL 1
#define HEAP_LFH 2
int __cdecl _tmain()
{
BOOL bResult;
HANDLE hHeap;
ULONG HeapInformation;
//
// Get a handle to the default process heap.
//
hHeap = GetProcessHeap();
if (hHeap == NULL) {
_tprintf(TEXT("Failed to retrieve default process heap with LastError %d.\n"),
GetLastError());
return 1;
}
//
// Query heap features that are enabled.
//
bResult = HeapQueryInformation(hHeap,
HeapCompatibilityInformation,
&HeapInformation,
sizeof(HeapInformation),
NULL);
if (bResult == FALSE) {
_tprintf(TEXT("Failed to retrieve heap features with LastError %d.\n"),
GetLastError());
return 1;
}
//
// Print results of the query.
//
_tprintf(TEXT("HeapCompatibilityInformation is %d.\n"), HeapInformation);
switch(HeapInformation)
{
case HEAP_STANDARD:
_tprintf(TEXT("The default process heap is a standard heap.\n"));
break;
case HEAP_LAL:
_tprintf(TEXT("The default process heap supports look-aside lists.\n"));
break;
case HEAP_LFH:
_tprintf(TEXT("The default process heap has the low-fragmentation ") \
TEXT("heap enabled.\n"));
break;
default:
_tprintf(TEXT("Unrecognized HeapInformation reported for the default ") \
TEXT("process heap.\n"));
break;
}
return 0;
}
需求:
|
Minimum supported client |
Windows XP [桌面应用程序 | Windows Store 程序] |
|
Minimum supported server |
Windows 2003 服务器版 [桌面应用程序 | Windows Store 程序] |
|
Minimum supported phone |
Windows Phone 8 |
|
Header |
HeapApi.h (包含于 Windows.h); |
|
Library |
Kernel32.lib |
|
DLL |
Kernel32.dll |




