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

Allocates APU physical memory.

## Syntax

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

### Parameters

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

Virtual address returned.

*physicalAddress*   \_Result\_zeroonfailure\_ \_Out\_opt\_\
Type: APU\_ADDRESS\*

`APU_ADDRESS` returned; for use with the APU.

*sizeInBytes*   \_In\_\
Type: UINT32

Size of the allocation, in bytes.

*alignmentInBytes*   \_In\_\
Type: UINT32

Alignment, in bytes. Must be a power of 2 and greater than or equal to 4.

*flags*\
Type: UINT32

Allocation flag: `APU_ALLOC_CACHED` or `APU_ALLOC_NONCACHED`.

### Return value

Type: HRESULT

This method can return the following values:

| Return code    | Description                                                                                                                                                            |
| :------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| S\_OK          | Success                                                                                                                                                                |
| E\_INVALIDARG  | Invalid argument, such as virtual address == nullptr, size == 0, alignment == 0, (alignment & 0x3) != 0, (alignment & (alignment - 1)) != 0, or an invalid flags value |
| E\_OUTOFMEMORY | Memory allocation failure                                                                                                                                              |

## Remarks

The virtual and physical addresses that are returned represent different views of the same address space. Freeing one invalidates the other. To free an allocation, use [ApuFree](/reference/audio/apu/functions/apufree).

## Requirements

**Header:** apu.h

**Library:** acphal.lib

**Supported platforms:** XBOX One family consoles and XBOX Series consoles

## Conceptual documentation

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

## See also

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


## Related topics

- [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)
- [APU (Audio Processing Unit)](/reference/audio/apu/apu_members.md)
