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

# game_chat_allocate_memory_callback

> 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](/reference/chat/gamechat2/functions/game_chat_free_memory_callback) 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](/reference/chat/gamechat2/gamechat2_members)\
[chat\_manager::get\_memory\_callbacks](/reference/chat/gamechat2/classes/chat_manager/methods/chat_manager_get_memory_callbacks)\
[chat\_manager::set\_memory\_callbacks](/reference/chat/gamechat2/classes/chat_manager/methods/chat_manager_set_memory_callbacks)


## Related topics

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