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

# XMEM_SET_ALLOCATION_HOOKS

> XMEM_SET_ALLOCATION_HOOKS

# XMEM\_SET\_ALLOCATION\_HOOKS

Used by titles to register memory allocation hooks.

## Syntax

```cpp theme={null}
#define XMEM_SET_ALLOCATION_HOOKS(AllocRoutine, FreeRoutine) \
    __declspec(dllexport) XMEM_ALLOCATION_HOOKS __XMemAllocationHooks__ = { AllocRoutine, FreeRoutine };
```

### Parameters

*AllocRoutine*   *In*

Type: PXMEMALLOC\_ROUTINE

Pointer to the title's allocation function. See the [XMEMALLOC\_ROUTINE](/reference/system/xmem/functions/xmemalloc_routine) topic for the definition of this function.

*FreeRoutine*   *In*\
Type: PXMEMFREE\_ROUTINE

Pointer to the title's deallocation function. See the [XMEMFREE\_ROUTINE](/reference/system/xmem/functions/xmemalloc_routine) topic for the definition of this function.

## Remarks

Allocations can be monitored (or overridden) with a title provided callback through the **XMEM\_SET\_ALLOCATION\_HOOKS** macro. With proper use of this macro, titles can track every allocation made from the title code as well as the platform code.

If titles choose not to provide their own allocation hooks, **XMemAllocDefault** and **XMemFreeDefault** will be used instead (see xmem.h for the declaration of these hooks.) If titles desire to provide allocation hooks for the sake of tracking, but do not wish to implement their own allocator, they can call into the default allocator directly.

It is important to provide an implementation for both [XMEMALLOC\_ROUTINE](/reference/system/xmem/functions/xmemalloc_routine) and [XMEMFREE\_ROUTINE](/reference/system/xmem/functions/xmemfree_routine) if you hook them; hooking only one of them will be considered an error.

The title provided hooks are exported from the game executable and are bound at load time of xmem.dll (normally the time that the game is launched).

<Note>The functions registered by XMemSetAllocationHooks must be defined within the game exe to ensure that the addresses are statically populated.  If the function pointers provided refer to functions in DLLs that is referenced by the game exe, the compiler must emit static initializer code to populate the memory that may execute after the platform has queried for the override hooks resulting in unpredictable behavior.  A warning will appear in the debugger output window if the platform detects this may have occurred.</Note>

## Requirements

**Header:** xmem.h

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

## See also

[XMem reference](/reference/system/xmem/xmem_members)\
[XMEM\_ALLOCATION\_HOOKS](/reference/system/xmem/structs/xmem_allocation_hooks)\
[XMEMALLOC\_ROUTINE](/reference/system/xmem/functions/xmemalloc_routine)\
[XMEMFREE\_ROUTINE](/reference/system/xmem/functions/xmemalloc_routine)


## Related topics

- [XMEM_ALLOCATION_HOOKS](/reference/system/xmem/structs/xmem_allocation_hooks.md)
- [XMemFreeDefault](/reference/system/xmem/functions/xmemfreedefault.md)
- [XMemSetAllocationHooks](/reference/system/xmem/functions/xmemsetallocationhooks.md)
- [XMemSetWin32HeapTrackingHooks](/reference/system/xmem/functions/xmemsetwin32heaptrackinghooks.md)
