> ## 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.

# XMemSetAllocationHooks

> XMemSetAllocationHooks

# XMemSetAllocationHooks

此 API 已被取代。請改為參閱 [XMEM\_ALLOCATION\_HOOKS](/zh-TW/reference/system/xmem/structs/xmem_allocation_hooks)。

供遊戲用來註冊記憶體配置攔截程序。

## 語法

```cpp theme={null}
VOID XMemSetAllocationHooks(  
         PXMEMALLOC_ROUTINE AllocRoutine,  
         PXMEMFREE_ROUTINE FreeRoutine  
)  
```

### 參數

*AllocRoutine*   \_In\_\
類型：PXMEMALLOC\_ROUTINE

指向遊戲配置函式的指標。如需此函式的定義，請參閱 [XMEMALLOC\_ROUTINE](/zh-TW/reference/system/xmem/functions/xmemalloc_routine) 主題。

*FreeRoutine*   \_In\_\
類型：PXMEMFREE\_ROUTINE

指向遊戲解除配置函式的指標。如需此函式的定義，請參閱 [XMEMFREE\_ROUTINE](/zh-TW/reference/system/xmem/functions/xmemfree_routine) 主題。

### 傳回值

類型：VOID

## 備註

可以透過 **XMemSetAllocationHooks** 函式，使用遊戲提供的回呼來監視 (或覆寫) 配置。妥善使用此 API，遊戲就能追蹤從遊戲程式碼以及大部分平台程式碼進行的幾乎所有配置。

如果遊戲選擇不提供自己的配置攔截程序，則會改用 **XMemAllocDefault** 和 **XMemFreeDefault** (如需這些攔截程序的宣告，請參閱 xmem.h)。如果遊戲想要提供配置攔截程序以進行追蹤，但不想實作自己的配置器，則可以直接呼叫預設配置器。

如果您攔截 [XMEMALLOC\_ROUTINE](/zh-TW/reference/system/xmem/functions/xmemalloc_routine) 和 [XMEMFREE\_ROUTINE](/zh-TW/reference/system/xmem/functions/xmemfree_routine)，務必為兩者都提供實作；只攔截其中一個將被視為錯誤。

## 需求

**標頭：** xmem.h

**程式庫：** xmem.lib

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

## 另請參閱

[XMem 參考](/zh-TW/reference/system/xmem/xmem_members)\
[XMEMALLOC\_ROUTINE](/zh-TW/reference/system/xmem/functions/xmemalloc_routine)\
[XMEMFREE\_ROUTINE](/zh-TW/reference/system/xmem/functions/xmemfree_routine)


## Related topics

- [XMemSetAllocationHooks](/reference/system/xmem/functions/xmemsetallocationhooks.md)
- [XMEM_ALLOCATION_HOOKS](/reference/system/xmem/structs/xmem_allocation_hooks.md)
