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

# PFMultiplayerAllocateMemoryCallback

> Reference for the PFMultiplayerAllocateMemoryCallback used by the PlayFab Multiplayer C/C++ library to request a dynamically allocated memory buffer.

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

## Syntax

```cpp theme={null}
typedef
void* (*PFMultiplayerAllocateMemoryCallback)(  
    size_t size,  
    uint32_t memoryTypeId  
)  
```

### Parameters

**`size`**   size\_t

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

**`memoryTypeId`**   uint32\_t

An opaque identifier representing the PlayFab Multiplayer library internal category of memory being allocated. This value should be ignored.

### Return value

Type: void\*

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

## Remarks

This callback is optionally installed using the [PFMultiplayerSetMemoryCallbacks()](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pfmultiplayer/functions/pfmultiplayersetmemorycallbacks) method. <br /><br /> The callback must allocate and return a pointer to a contiguous block of memory of the specified size that will remain valid until the title's corresponding [PFMultiplayerFreeMemoryCallback](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pfmultiplayer/callbacks/pfmultiplayerfreememorycallback) is invoked to release it. If this is not possible, the callback must return nullptr to fail the allocation. Memory allocation failures are sometimes considered benign but will usually cause current PlayFab Multiplayer library operation(s) to fail.   <br /><br /> Every non-nullptr returned by this method will be subsequently passed to the corresponding [PFMultiplayerFreeMemoryCallback](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pfmultiplayer/callbacks/pfmultiplayerfreememorycallback) once the memory is no longer needed.

## Requirements

**Header:** PFMultiplayer.h

## See also

[PFMultiplayer members](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pfmultiplayer/pfmultiplayer_members)\
[PFMultiplayerFreeMemoryCallback](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pfmultiplayer/callbacks/pfmultiplayerfreememorycallback)\
[PFMultiplayerSetMemoryCallbacks](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pfmultiplayer/functions/pfmultiplayersetmemorycallbacks)


## Related topics

- [PFMultiplayerSetMemoryCallbacks](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pfmultiplayer/functions/pfmultiplayersetmemorycallbacks.md)
- [PFMultiplayerFreeMemoryCallback](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pfmultiplayer/callbacks/pfmultiplayerfreememorycallback.md)
- [PFMultiplayer C/C++ API overview - PFMultiplayer.h](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pfmultiplayer/pfmultiplayer_members.md)
- [PartyAllocateMemoryCallback](/services/playfab/multiplayer/networking/reference/callbacks/partyallocatememorycallback.md)
- [game_chat_allocate_memory_callback](/reference/chat/gamechat2/functions/game_chat_allocate_memory_callback.md)
