Overview
The PlayFab Unified SDK gives developers precise control over memory usage by supporting custom allocation hooks, explicit resource cleanup, and safe async operations handling. This makes it suitable for high-performance or resource-constrained environments such as games and embedded platforms.Custom Memory Allocation
The SDK allows you to define custom memory allocation and deallocation functions usingPFMemoryHooks. This lets you integrate the SDK into your existing memory management systems, such as arenas, pools, or platform-specific allocators.
Setting Custom Memory Hooks
- Hooks must be set before calling
PFServicesInitialize. - They cannot be changed once the SDK is initialized.
- If not set, the SDK defaults to standard allocation (
malloc/free).
Asynchronous Operations
Most API calls in the SDK are asynchronous. Each async call requires a validXAsyncBlock which must remain alive for the duration of the request.
Using XAsyncBlock Safely
- Don’t stack-allocate
XAsyncBlockunless you can guarantee its lifetime. - Release ownership if dynamically allocated, and clean up in the callback.
- Avoid capturing invalidated references or pointers in the lambda.
Resource Cleanup
The SDK uses handles (e.g.,PFEntityHandle, PFServiceConfigHandle) that must be explicitly closed when no longer needed.
Closing Handles and Uninitializing
- Always close PlayFab handles to prevent leaks.
- Wait for
PFServicesUninitializeAsyncto complete before shutting down.
Best Practices
- Set memory hooks early: Before any other PlayFab API calls.
- Avoid memory leaks: Close handles and manage async resources carefully.
- Use memory profilers: Especially on platforms with tight memory budgets.
- Use pooled allocators: For performance-critical or frequent allocations.
