Managing Memory Allocations
With the C API in the PlayFab Services SDK, you can specify a function callback that the SDK calls whenever it tries to allocate memory. If you don’t specify function callbacks, the SDK uses standard memory allocation routines. To manually specify your memory routines, you can take the following steps:- At the start of the game:
- Call PFMemSetFunctions to specify the allocation callbacks for assigning and releasing memory.
- Call PFInitialize to initialize the PlayFab Core library.
- Call PFServicesInitialize to initialize the PlayFab Services library.
The order matters. PFMemSetFunctions must come before PFInitialize, and PFInitialize must come before PFServicesInitialize. If you skip the explicit PFInitialize call, PFServicesInitialize initializes Core internally—but at that point your memory hooks aren’t applied yet, so the SDK uses default allocation routines instead.
-
While the game is running:
- Any calls into the SDK that allocate or free memory call the specified memory handling callbacks.
-
When the game exits:
- Call PFServicesUninitializeAsync to reclaim all resources associated with PlayFab Services.
- Call PFUninitializeAsync to reclaim all resources associated with PlayFab Core.
- Clean up your game’s custom memory manager.
