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

# XMemVirtualQuery

> XMemVirtualQuery

# XMemVirtualQuery

擷取呼叫處理序之虛擬位址空間中某個分頁範圍的相關資訊。

## 語法

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

### 參數

*Process*   \_In\_\
類型：HANDLE

處理序控制代碼，通常是透過呼叫 [GetCurrentProcess](https://learn.microsoft.com/windows/desktop/api/processthreadsapi/nf-processthreadsapi-getcurrentprocess) 取得。

*Address*   \_In\_opt\_\
類型：PVOID

要查詢之分頁區域基底位址的指標。此值會無條件捨去至下一個分頁邊界。如果此參數設定為高於處理序可存取之最高記憶體位址的位址，函式會失敗，且錯誤碼會設定為 **ERROR\_INVALID\_PARAMETER**。

*Buffer*   \_Out\_\
類型：PXMEM\_BASIC\_INFORMATION

[XMEM\_BASIC\_INFORMATION](https://docs.xbox.com/zh-TW/reference/system/xmem/structs/xmem_basic_information.md) 結構的指標，其中會傳回指定分頁範圍的相關資訊。

### 傳回值

類型：BOOL

如果成功，則傳回 `TRUE`；否則傳回 `FALSE`。若要取得延伸錯誤資訊，請呼叫 [GetLastError](https://msdn.microsoft.com/library/windows/desktop/ms679360\(v=vs.85\).aspx)。

## 備註

工具可以傳遞遠端處理序的控制代碼，以便從目前處理序外部查詢遊戲。

如果查詢的記憶體區域有相關聯的選擇性四字元代碼標籤，該標籤會包含在 `TagFourCC` 欄位中，並以 24 位元表示法編碼在 `Buffer` 中所傳回之 `XMEM_BASIC_INFORMATION` 結構的 `TagCode` 欄位中。否則，`TagFourCC` 欄位會填入 NULL 值，且應忽略 `TagCode` 欄位。如需標籤的詳細資訊，請參閱 [XMemVirtualAlloc](https://docs.xbox.com/zh-TW/reference/system/xmem/functions/xmemvirtualalloc.md)。

範例：若要計算直接呼叫 'XMemVirtualAlloc' 所配置之記憶體的總記憶體使用量，需要結合使用 'XMemSetOption' 和 'XMemVirtualQuery'。

```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;
}
```

## 需求

**標頭：** xmem.h

**程式庫：** xmem.lib

**支援的平台：** XBOX One 系列主機和 XBOX Series 主機

## 另請參閱

[XMEM\_BASIC\_INFORMATION](https://docs.xbox.com/zh-TW/reference/system/xmem/structs/xmem_basic_information.md)\
[XMem](https://docs.xbox.com/zh-TW/reference/system/xmem/xmem_members.md)


## Related topics

- [使用 Microsoft GDK Game OS 記憶體管理員](https://docs.xbox.com/zh-TW/build/console-features/memory/system-memory-working.md)
- [XMemMakeTag](https://docs.xbox.com/zh-TW/reference/system/xmem/functions/xmemmaketag.md)
- [XMemMapPhysicalPages](https://docs.xbox.com/zh-TW/reference/system/xmem/functions/xmemmapphysicalpages.md)
- [Query](https://docs.xbox.com/zh-TW/reference/system/dstorage/interfaces/IDStorageQueueX/methods/idstoragequeuex_query.md)
- [XMemMapPhysicalPagesScatter](https://docs.xbox.com/zh-TW/reference/system/xmem/functions/xmemmapphysicalpagesscatter.md)
