Memory Manager API for low-level native plug-ins
Profiling low-level native plug-ins
IUnityMemoryManager API referenceThis pages provides the API reference for the IUnityMemoryManager
interface.
UnityAllocator* (UNITY_INTERFACE_API * CreateAllocator)(const char* areaName, const char* objectName);
Creates a new Allocator object which can allocate blocks of memory.
DestroyAllocator Declarationvoid(UNITY_INTERFACE_API * DestroyAllocator)(UnityAllocator * allocator);
Deletes an existing Allocator object.
Allocate Declarationvoid* (UNITY_INTERFACE_API * Allocate)(UnityAllocator * allocator, size_t size, size_t align, const char* file, int32_t line);
Allocates a block of memory using an existing allocator. This method returns a pointer to the newly allocated memory.
Deallocate Declarationvoid(UNITY_INTERFACE_API * Deallocate)(UnityAllocator * allocator, void* ptr, const char* file, int32_t line);
Deallocates the memory that the specified pointer points to. This doesnât set the pointer to NULL.
Reallocate Declarationvoid* (UNITY_INTERFACE_API * Reallocate)(UnityAllocator * allocator, void* ptr, size_t size, size_t align, const char* file, int32_t line);
Reallocates an existing pointer to point to a different block of memory.
Implementation exampleBelow is an example implementation of the IUnityMemoryManager
interface.
#include "IUnityInterface.h"
#include "IUnityMemoryManager.h"
#include <cstdint>
static IUnityMemoryManager* s_MemoryManager = NULL;
static UnityAllocator* s_Alloc = NULL;
extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginLoad(IUnityInterfaces * unityInterfaces)
{
s_MemoryManager = unityInterfaces->Get<IUnityMemoryManager>();
if (s_MemoryManager == NULL)
return;
// Create an allocator. This allows you to see the allocation root in the profiler when taking snapshots. Under plug-ins-native - Plugin Backend Allocator
// All memory allocated here also goes under kMemNativePlugin
s_Alloc = s_MemoryManager->CreateAllocator("plug-ins-native", "Plugin Backend Allocator");
}
extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginUnload()
{
//Free allocator
s_MemoryManager->DestroyAllocator(s_Alloc);
s_Alloc = NULL;
s_MemoryManager = NULL;
}
void DoMemoryOperations()
{
// Allocate 1KB memory
void* mem = s_MemoryManager->Allocate(s_Alloc, 1 * 1024, 16, __FILE__, __LINE__);
// Reallocate the same pointer with 2KB
mem = s_MemManager->Reallocate(s_Alloc, mem, 2 * 1024, 16, __FILE__, __LINE__);
// Delete allocated memory
s_MemoryManager->Deallocate(s_Alloc, mem, __FILE__, __LINE__);
}
Additional resources
Memory Manager API for low-level native plug-ins
Profiling low-level native plug-ins
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4