VirtualQuery function (memoryapi.h)
Retrieves information about a range of pages in the virtual address space of the calling process.
To retrieve information about a range of pages in the address space of another process, use the VirtualQueryEx function.
SIZE_T VirtualQuery( LPCVOID lpAddress, PMEMORY_BASIC_INFORMATION lpBuffer, SIZE_T dwLength );
A pointer to the base address of the region of pages to be queried. This value is rounded down to the next page boundary. To determine the size of a page on the host computer, use the GetSystemInfo function.
If lpAddress specifies an address above the highest memory address accessible to the process, the function fails with ERROR_INVALID_PARAMETER.
A pointer to a MEMORY_BASIC_INFORMATION structure in which information about the specified page range is returned.
The size of the buffer pointed to by the lpBuffer parameter, in bytes.
The return value is the actual number of bytes returned in the information buffer.
If the function fails, the return value is zero. To get extended error information, call GetLastError. Possible error values include ERROR_INVALID_PARAMETER.
VirtualQuery provides information about a region of consecutive pages beginning at a specified address that share the following attributes:
- The state of all pages is the same (MEM_COMMIT, MEM_RESERVE, MEM_FREE, MEM_PRIVATE, MEM_MAPPED, or MEM_IMAGE).
- If the initial page is not free, all pages in the region are part of the same initial allocation of pages created by a single call to VirtualAlloc, MapViewOfFile, or one of the following extended versions of these functions: VirtualAllocEx, VirtualAllocExNuma, MapViewOfFileEx, MapViewOfFileExNuma.
- The access granted to all pages is the same (PAGE_READONLY, PAGE_READWRITE, PAGE_NOACCESS, PAGE_WRITECOPY, PAGE_EXECUTE, PAGE_EXECUTE_READ, PAGE_EXECUTE_READWRITE, PAGE_EXECUTE_WRITECOPY, PAGE_GUARD, or PAGE_NOCACHE).
If a shared copy-on-write page is modified, it becomes private to the process that modified the page. However, the VirtualQuery function will continue to report such pages as MEM_MAPPED (for data views) or MEM_IMAGE (for executable image views) rather than MEM_PRIVATE. To detect whether copy-on-write has occurred for a specific page, either access the page or lock it using the VirtualLock function to make sure the page is resident in memory, then use the QueryWorkingSetEx function to check the Shared bit in the extended working set information for the page. If the Shared bit is clear, the page is private.
This function reports on a region of pages in the memory of the calling process, and the VirtualQueryEx function reports on a region of pages in the memory of a specified process.
|Minimum supported client||Windows XP [desktop apps | UWP apps]|
|Minimum supported server||Windows Server 2003 [desktop apps | UWP apps]|
|Header||memoryapi.h (include Windows.h, Memoryapi.h)|