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

每次 Game Chat 库必须动态分配新的内存缓冲区时调用的回调。

## 语法

```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
    );
```

### 参数

*size*   \_In\_\
类型:size\_t

要进行的分配的大小。此值永远不会为零。

*memoryTypeId*   \_In\_\
类型:uint32\_t

指向指定大小的已分配内存块的指针,如果分配失败则为空指针。

## 备注

此回调可选地通过 chat\_manager::set\_memory\_callbacks() 方法安装。

回调必须分配并返回指向指定大小的连续内存块的指针,该内存块在应用对应的 [game\_chat\_free\_memory\_callback](/reference/chat/gamechat2/functions/game_chat_free_memory_callback) 被调用以释放它之前一直保持有效。
如果无法做到这一点,回调必须返回空指针以使分配失败。内存分配失败有时被视为良性,但通常会导致当前 Game Chat 库的操作失败。

## 需求

**头文件:** GameChat2.h

**支持的平台:** Windows、XBOX One 家族主机以及 XBOX Series 主机

## 另请参阅

[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

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