Skip to main content

XblMemAllocFunction

A callback that the XBOX Services API (XSAPI) invokes each time it needs a new memory buffer.

Syntax

Parameters

size   _In_
Type: size_t
The size of the allocation to be made. This value is never zero. memoryType   _In_
Type: HCMemoryType
An opaque identifier that represents the internal category of memory being allocated.

Return value

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

Remarks

This callback is optional. Install it, together with an XblMemFreeFunction callback, by calling XblMemSetFunctions before you call XblInitialize. Both callbacks must be set together. The callback must allocate and return a pointer to a contiguous block of memory of the specified size. The block must remain valid until XSAPI passes the pointer to the corresponding XblMemFreeFunction callback. Every non-null pointer that the callback returns is passed to the XblMemFreeFunction callback when XSAPI no longer needs the memory. XblMemSetFunctions also passes the callbacks to libHttpClient. If libHttpClient is already initialized, it keeps its existing memory hooks. If you install custom memory callbacks, wait for XblCleanupAsync to complete before you shut down your memory manager. If your app dispatches XSAPI work concurrently, make sure that any allocator state shared by the callbacks is safe for concurrent use. The following example installs callbacks that use malloc and free from <stdlib.h>.

Argument of

XblMemSetFunctions
XblMemGetFunctions

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
XblMemFreeFunction
Last modified on October 29, 2026