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

# ApuAlloc

> ApuAlloc

# ApuAlloc

分配 APU 物理内存。

## 语法

```cpp theme={null}
HRESULT ApuAlloc(  
         void** virtualAddress,  
         APU_ADDRESS* physicalAddress,  
         UINT32 sizeInBytes,  
         UINT32 alignmentInBytes = 4,  
         UINT32 flags = APU_ALLOC_CACHED  
)  
```

### 参数

*virtualAddress*   \_Result\_nullonfailure\_ \_Outptr\_result\_bytebuffer\_(sizeInBytes)\
类型:void\*\*

返回的虚拟地址。

*physicalAddress*   \_Result\_zeroonfailure\_ \_Out\_opt\_\
类型:APU\_ADDRESS\*

返回的 `APU_ADDRESS`;供 APU 使用。

*sizeInBytes*   \_In\_\
类型:UINT32

分配的大小,以字节为单位。

*alignmentInBytes*   \_In\_\
类型:UINT32

对齐值,以字节为单位。必须是 2 的幂且大于或等于 4。

*flags*\
类型:UINT32

分配标志:`APU_ALLOC_CACHED` 或 `APU_ALLOC_NONCACHED`。

### 返回值

类型:HRESULT

此方法可以返回以下值:

| 返回代码           | 描述                                                                                                                                 |
| :------------- | :--------------------------------------------------------------------------------------------------------------------------------- |
| S\_OK          | 成功                                                                                                                                 |
| E\_INVALIDARG  | 无效参数,例如 virtual address == nullptr、size == 0、alignment == 0、(alignment & 0x3) != 0、(alignment & (alignment - 1)) != 0 或无效的 flags 值 |
| E\_OUTOFMEMORY | 内存分配失败                                                                                                                             |

## 备注

返回的虚拟地址和物理地址表示同一地址空间的不同视图。释放其中一个会使另一个失效。若要释放已分配的内存,请使用 [ApuFree](/reference/audio/apu/functions/apufree)。

## 要求

**头文件:** apu.h

**库:** acphal.lib

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

## 概念文档

* [XMA2 概述](/build/console-features/audio/overviews/xma2-overview)

## 另请参阅

[ApuFree](/reference/audio/apu/functions/apufree)\
[APU](/reference/audio/apu/apu_members)


## Related topics

- [ApuFree](/zh-CN/reference/audio/apu/functions/apufree.md)
- [ApuMapApuAddress](/zh-CN/reference/audio/apu/functions/apumapapuaddress.md)
- [ApuMapVirtualAddress](/zh-CN/reference/audio/apu/functions/apumapvirtualaddress.md)
- [XMA2 概述](/zh-CN/build/console-features/audio/overviews/xma2-overview.md)
- [ApuIsVirtualAddressValid](/zh-CN/reference/audio/apu/functions/apuisvirtualaddressvalid.md)
