> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XMemVirtualQuery

> XMemVirtualQuery

# XMemVirtualQuery

Retrieves information about a range of pages in the virtual address space of the calling process.

<a id="syntaxSection" />

## Syntax

```cpp theme={null}
BOOL XMemVirtualQuery(  
         HANDLE Process,  
         PVOID Address,  
         PXMEM_BASIC_INFORMATION Buffer  
)  
```

<a id="parametersSection" />

### Parameters

*Process*   \_In\_\
Type: HANDLE

A process handle, typically obtained by calling [GetCurrentProcess](https://learn.microsoft.com/windows/desktop/api/processthreadsapi/nf-processthreadsapi-getcurrentprocess).

*Address*   \_In\_opt\_\
Type: PVOID

A pointer to the base address of the region of pages to be queried. This value is rounded down to the next page boundary. If this parameter is set to an address above the highest memory address accessible to the process, the function fails with an error code set to **ERROR\_INVALID\_PARAMETER**.

*Buffer*   \_Out\_\
Type: PXMEM\_BASIC\_INFORMATION

A pointer to a [XMEM\_BASIC\_INFORMATION](/reference/system/xmem/structs/xmem_basic_information) structure in which information about the specified page range is returned.

<a id="retvalSection" />

### Return value

Type: BOOL

Returns `TRUE` if successful; otherwise, `FALSE`. To get extended error information, call [GetLastError](https://msdn.microsoft.com/library/windows/desktop/ms679360\(v=vs.85\).aspx).

<a id="remarksSection" />

## Remarks

Tools can pass the handle to a remote process, to query the title from outside of the current process.

If the queried region of memory has an optional four-character code tag associated with it, the tag is included in the `TagFourCC` field and encoded as a 24-bit representation in the `TagCode` field of the `XMEM_BASIC_INFORMATION` structure returned in `Buffer`. Otherwise, the `TagFourCC` field is filled with NULL values and the `TagCode` field should be ignored. For more information about tags, see [XMemVirtualAlloc](/reference/system/xmem/functions/xmemvirtualalloc).

Example: To compute the total memory usage for the memory that is allocated by a direct call to 'XMemVirtualAlloc', a combination of 'XMemSetOption' and 'XMemVirtualQuery' is needed.

```cpp theme={null}
// To enable commit tracking
XMEM_OPTION option;
option.Option = eXMEMOPT_XMEMALLOCDEFAULT_TAG_VIRTUALALLOC;
option.u.Bool = TRUE;
XMemSetOption(option);

// To query the total commit
SIZE_T address = 0;
SIZE_T commitSize = 0;
XMEM_BASIC_INFORMATION info; = {};
while (XMemVirtualQuery(GetCurrentProcess(), (PVOID)address, &info))
{
        if ((info.State & MEM_COMMIT) &&
                (*(PDWORD)(info.TagFourCC) == *(PDWORD)("XmVA"))) {

                commitSize += info.RegionSize;
        }

        address += info.RegionSize;
}
```

<a id="requirementsSection" />

## Requirements

**Header:** xmem.h

**Library:** xmem.lib

**Supported platforms:** XBOX One family consoles and XBOX Series consoles

<a id="seealsoSection" />

## See also

[XMEM\_BASIC\_INFORMATION](/reference/system/xmem/structs/xmem_basic_information)\
[XMem](/reference/system/xmem/xmem_members)


## Related topics

- [Working with the Microsoft GDK Game OS memory manager](/build/console-features/memory/system-memory-working.md)
- [XMemMakeTag](/reference/system/xmem/functions/xmemmaketag.md)
- [XMemMapPhysicalPagesScatter](/reference/system/xmem/functions/xmemmapphysicalpagesscatter.md)
- [XMemMapPhysicalPages](/reference/system/xmem/functions/xmemmapphysicalpages.md)
- [PFVirtualCurrencyRechargeTime](/services/playfab/api-references/c/pftypes/structs/pfvirtualcurrencyrechargetime.md)
