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

# XblMemSetFunctions

> XblMemSetFunctions

Optionally sets the memory hook functions to allow callers to route memory allocations to their own memory manager.

## Syntax

```cpp theme={null}
HRESULT XblMemSetFunctions(  
         XblMemAllocFunction memAllocFunc,  
         XblMemFreeFunction memFreeFunc  
)  
```

### Parameters

*memAllocFunc*   \_In\_opt\_\
Type: [XblMemAllocFunction](https://docs.xbox.com/reference/live/xsapi-c/xbox_live_global_c/functions/xblmemallocfunction.md)

A pointer to the custom allocation callback to use, or a null pointer to restore the default.

*memFreeFunc*   \_In\_opt\_\
Type: [XblMemFreeFunction](https://docs.xbox.com/reference/live/xsapi-c/xbox_live_global_c/functions/xblmemfreefunction.md)

A pointer to the custom freeing callback to use, or a null pointer to restore the default.

### Return value

Type: HRESULT

HRESULT return code for this API operation. Possible error codes include the following. This list isn't exhaustive.

| Return code | Description |
| - | - |
| E\_XBL\_ALREADY\_INITIALIZED | The library is already initialized. Call this function before [XblInitialize](https://docs.xbox.com/reference/live/xsapi-c/xbox_live_global_c/functions/xblinitialize.md). |
| E\_INVALIDARG | Only one of *memAllocFunc* and *memFreeFunc* is null. |

## Remarks

Call this function before [XblInitialize](https://docs.xbox.com/reference/live/xsapi-c/xbox_live_global_c/functions/xblinitialize.md). You can't call it again until [XblCleanupAsync](https://docs.xbox.com/reference/live/xsapi-c/xbox_live_global_c/functions/xblcleanupasync.md) completes. This function lets the app install custom memory allocation routines to service all requests for new memory buffers instead of using the default allocation routines. The *memAllocFunc* and *memFreeFunc* parameters can be null pointers to restore the default routines. Both callback pointers must be null or both must be non-null. Mixing custom and default routines isn't permitted.

This function also passes the callbacks to libHttpClient by calling [HCMemSetFunctions](https://docs.xbox.com/reference/live/httpclient/httpclient/functions/hcmemsetfunctions.md). If libHttpClient is already initialized, it keeps its existing memory hooks, and this function still succeeds.

## Requirements

**Header:** xbox\_live\_global\_c.h

**Library:** Microsoft.Xbox.Services.142.C.lib or Microsoft.Xbox.Services.143.C.lib

## See also

[xbox\_live\_global\_c](https://docs.xbox.com/reference/live/xsapi-c/xbox_live_global_c/xbox_live_global_c_members.md)


## Related topics

- [XblMemGetFunctions](https://docs.xbox.com/reference/live/xsapi-c/xbox_live_global_c/functions/xblmemgetfunctions.md)
- [XblMemAllocFunction](https://docs.xbox.com/reference/live/xsapi-c/xbox_live_global_c/functions/xblmemallocfunction.md)
- [XblMemFreeFunction](https://docs.xbox.com/reference/live/xsapi-c/xbox_live_global_c/functions/xblmemfreefunction.md)
- [XblInitialize](https://docs.xbox.com/reference/live/xsapi-c/xbox_live_global_c/functions/xblinitialize.md)
- [XblCleanupAsync](https://docs.xbox.com/reference/live/xsapi-c/xbox_live_global_c/functions/xblcleanupasync.md)
