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

Defines the syntax of the memory allocation routines, [XMemAlloc](https://docs.xbox.com/reference/system/xmem/functions/xmemalloc.md) and `XMemAllocDefault`.

## Syntax

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

### Parameters

*Size*   \_In\_\
Type: SIZE\_T

The size of the memory block that is being requested, in bytes.

*Attributes*   \_In\_\
Type: ULONGLONG

The attributes of the memory allocation. For more information, see [XALLOC\_ATTRIBUTES](https://docs.xbox.com/reference/system/xmem/structs/xalloc_attributes.md).

### Return value

Type: PVOID

A pointer to the allocated memory, if successful; otherwise, `NULL`.

## Remarks

This function definition is used in the [XMEM\_ALLOCATION\_HOOKS](https://docs.xbox.com/reference/system/xmem/structs/xmem_allocation_hooks.md) structure to define the [XMemAlloc](https://docs.xbox.com/reference/system/xmem/functions/xmemalloc.md) and `XMemAllocDefault` functions. Similarly, the [XMEMFREE\_ROUTINE](https://docs.xbox.com/reference/system/xmem/functions/xmemfree_routine.md) function definition is used to define the [XMemFree](https://docs.xbox.com/reference/system/xmem/functions/xmemfree.md) and `XMemFreeDefault` functions.

> [!NOTE]
>
> Source code for the default implementation of `XMemAlloc` is installed as part of the Microsoft Game Development Kit (GDK). For more information, see the `XMemAllocDefault` function in `\GXDK\gameKit\Source\amd64\heap.c`.

## Requirements

**Header:** xmem.h

**Library:** xmem.lib

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

## See also

[Diagnostics and memory tracking](https://docs.xbox.com/build/console-features/memory/system-memory-diagnostics.md)\
[XMem](https://docs.xbox.com/reference/system/xmem/xmem_members.md)\
[XMemAllocDefault](https://docs.xbox.com/reference/system/xmem/functions/xmemallocdefault.md)


## Related topics

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