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

# game_chat_allocate_memory_callback

> game_chat_allocate_memory_callback

A callback invoked every time a new memory buffer must be dynamically allocated by the Game Chat library.

## Syntax

```cpp theme={null}
typedef
_Ret_maybenull_
_Post_writable_byte_size_(size) void *
(game_chat_callback * game_chat_allocate_memory_callback)(
    _In_ size_t size,
    _In_ uint32_t memoryTypeId
    );
```

### Parameters

*size*   \_In\_\
Type: size\_t

The size of the allocation to be made. This value will never be zero.

*memoryTypeId*   \_In\_\
Type: uint32\_t

A pointer to an allocated block of memory of the specified size, or a null pointer if allocation failed.

## Remarks

This callback is optionally installed using the chat\_manager::set\_memory\_callbacks() method.

The callback must allocate and return a pointer to a contiguous block of memory of the specified size that will
remain valid until the app's corresponding [game\_chat\_free\_memory\_callback](https://docs.xbox.com/reference/chat/gamechat2/functions/game_chat_free_memory_callback.md) is invoked to release it.
If this is not possible, the callback must return a null pointer to fail the allocation. Memory allocation failures
are sometimes considered benign but will usually cause current Game Chat library operation(s) to fail.

## Requirements

**Header:** GameChat2.h

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

## See also

[GameChat2 members](https://docs.xbox.com/reference/chat/gamechat2/gamechat2_members.md)\
[chat\_manager::get\_memory\_callbacks](https://docs.xbox.com/reference/chat/gamechat2/classes/chat_manager/methods/chat_manager_get_memory_callbacks.md)\
[chat\_manager::set\_memory\_callbacks](https://docs.xbox.com/reference/chat/gamechat2/classes/chat_manager/methods/chat_manager_set_memory_callbacks.md)


## Related topics

- [game_chat_free_memory_callback](https://docs.xbox.com/reference/chat/gamechat2/functions/game_chat_free_memory_callback.md)
- [get_memory_callbacks](https://docs.xbox.com/reference/chat/gamechat2/classes/chat_manager/methods/chat_manager_get_memory_callbacks.md)
- [set_memory_callbacks](https://docs.xbox.com/reference/chat/gamechat2/classes/chat_manager/methods/chat_manager_set_memory_callbacks.md)
- [GameChat2 members (API contents)](https://docs.xbox.com/reference/chat/gamechat2/gamechat2_members.md)
- [PFMultiplayerAllocateMemoryCallback](https://docs.xbox.com/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pfmultiplayer/callbacks/pfmultiplayerallocatememorycallback.md)
