> ## 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](/reference/system/xmem/structs/xmem_allocation_hooks)。

供游戏用于注册内存分配挂钩。

## 语法

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

### 参数

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

指向游戏的分配函数的指针。有关此函数的定义，请参阅 [XMEMALLOC\_ROUTINE](/reference/system/xmem/functions/xmemalloc_routine) 主题。

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

指向游戏的释放函数的指针。有关此函数的定义，请参阅 [XMEMFREE\_ROUTINE](/reference/system/xmem/functions/xmemfree_routine) 主题。

### 返回值

类型：VOID

## 备注

可以通过 **XMemSetAllocationHooks** 函数使用游戏提供的回调来监视（或重写）分配。通过正确使用此 API，游戏几乎可以跟踪游戏代码发出的每一次分配以及大部分平台代码的分配。

如果游戏选择不提供自己的分配挂钩，则会改用 **XMemAllocDefault** 和 **XMemFreeDefault**（请参阅 xmem.h 以了解这些挂钩的声明）。如果游戏希望为了跟踪而提供分配挂钩，但不希望实现自己的分配器，则可以直接调用默认分配器。

如果你要挂接分配相关函数，务必同时为 [XMEMALLOC\_ROUTINE](/reference/system/xmem/functions/xmemalloc_routine) 和 [XMEMFREE\_ROUTINE](/reference/system/xmem/functions/xmemfree_routine) 提供实现；仅挂接其中一个将被视为错误。

## 要求

**头文件：** xmem.h

**库：** xmem.lib

**支持的平台：** XBOX One 系列主机和 XBOX Series 主机

## 另请参阅

[XMem 参考](/reference/system/xmem/xmem_members)\
[XMEMALLOC\_ROUTINE](/reference/system/xmem/functions/xmemalloc_routine)\
[XMEMFREE\_ROUTINE](/reference/system/xmem/functions/xmemfree_routine)


## Related topics

- [XMEM_ALLOCATION_HOOKS](/zh-CN/reference/system/xmem/structs/xmem_allocation_hooks.md)
- [XMemSetWin32HeapTrackingHooks](/zh-CN/reference/system/xmem/functions/xmemsetwin32heaptrackinghooks.md)
- [XMemFreeDefault](/zh-CN/reference/system/xmem/functions/xmemfreedefault.md)
- [PFMemSetFunctions](/zh-CN/services/playfab/api-references/c/pfplatform/functions/pfmemsetfunctions.md)
- [PFMemoryHooks](/zh-CN/services/playfab/api-references/c/pfplatform/structs/pfmemoryhooks.md)
