> ## 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，或無效的旗標值 |
| E\_OUTOFMEMORY | 記憶體配置失敗 |

## 備註

傳回的虛擬位址和實體位址代表相同位址空間的不同檢視。釋放其中一個會使另一個失效。若要釋放配置，請使用 [ApuFree](/zh-TW/reference/audio/apu/functions/apufree)。

## 需求

**標頭：** apu.h

**程式庫：** acphal.lib

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

## 概念文件

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

## 另請參閱

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


## Related topics

- [ApuAlloc](/reference/audio/apu/functions/apualloc.md)
- [ApuMapApuAddress](/reference/audio/apu/functions/apumapapuaddress.md)
- [ApuFree](/reference/audio/apu/functions/apufree.md)
- [ApuMapVirtualAddress](/reference/audio/apu/functions/apumapvirtualaddress.md)
- [ApuIsVirtualAddressValid](/reference/audio/apu/functions/apuisvirtualaddressvalid.md)
