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

# XMEMALLOC_ROUTINE callback

> XMEMALLOC_ROUTINE callback

# XMEMALLOC\_ROUTINE callback

定义内存分配例程 [XMemAlloc](https://docs.xbox.com/zh-CN/reference/system/xmem/functions/xmemalloc.md) 和 `XMemAllocDefault` 的语法。

## 语法

```cpp theme={null}
PVOID XMEMALLOC_ROUTINE(  
         SIZE_T Size,  
         ULONGLONG Attributes  
)  
```

### 参数

*Size*   \_In\_\
类型：SIZE\_T

正在请求的内存块大小（以字节为单位）。

*Attributes*   \_In\_\
类型：ULONGLONG

内存分配的属性。有关更多信息，请参阅 [XALLOC\_ATTRIBUTES](https://docs.xbox.com/zh-CN/reference/system/xmem/structs/xalloc_attributes.md)。

### 返回值

类型：PVOID

如果成功，则为指向已分配内存的指针；否则为 `NULL`。

## 备注

此函数定义在 [XMEM\_ALLOCATION\_HOOKS](https://docs.xbox.com/zh-CN/reference/system/xmem/structs/xmem_allocation_hooks.md) 结构中用于定义 [XMemAlloc](https://docs.xbox.com/zh-CN/reference/system/xmem/functions/xmemalloc.md) 和 `XMemAllocDefault` 函数。同样，[XMEMFREE\_ROUTINE](https://docs.xbox.com/zh-CN/reference/system/xmem/functions/xmemfree_routine.md) 函数定义用于定义 [XMemFree](https://docs.xbox.com/zh-CN/reference/system/xmem/functions/xmemfree.md) 和 `XMemFreeDefault` 函数。

> [!NOTE]
>
> `XMemAlloc` 默认实现的源代码作为 Microsoft Game Development Kit (GDK) 的一部分进行安装。有关更多信息，请参阅 `\GXDK\gameKit\Source\amd64\heap.c` 中的 `XMemAllocDefault` 函数。

## 要求

**标头：** xmem.h

**库：** xmem.lib

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

## 请参阅

[诊断与内存跟踪](https://docs.xbox.com/zh-CN/build/console-features/memory/system-memory-diagnostics.md)\
[XMem](https://docs.xbox.com/zh-CN/reference/system/xmem/xmem_members.md)\
[XMemAllocDefault](https://docs.xbox.com/zh-CN/reference/system/xmem/functions/xmemallocdefault.md)


## Related topics

- [XMEMFREE_ROUTINE callback](https://docs.xbox.com/zh-CN/reference/system/xmem/functions/xmemfree_routine.md)
- [PHEAP_TRACK_ALLOC_ROUTINE callback](https://docs.xbox.com/zh-CN/reference/system/xmem/functions/pheap_track_alloc_routine.md)
- [PHEAP_TRACK_FREE_ROUTINE callback](https://docs.xbox.com/zh-CN/reference/system/xmem/functions/pheap_track_free_routine.md)
- [PHEAP_TRACK_REALLOC_ROUTINE callback](https://docs.xbox.com/zh-CN/reference/system/xmem/functions/pheap_track_realloc_routine.md)
- [XMEM_ALLOCATION_HOOKS](https://docs.xbox.com/zh-CN/reference/system/xmem/structs/xmem_allocation_hooks.md)
