This pages provides the API reference for the IUnityMemoryManager
interface.
UnityAllocator* (UNITY_INTERFACE_API * CreateAllocator)(const char* areaName, const char* objectName);
Parameter | Description |
---|---|
const char* areaName | The name for the broad category for this allocator. |
const char* objectName | The name for this specific allocator. |
Creates a new Allocator object which can allocate blocks of memory.
void(UNITY_INTERFACE_API * DestroyAllocator)(UnityAllocator * allocator);
Parameter | Description |
---|---|
UnityAllocator * allocator | The allocator to delete. |
Deletes an existing Allocator object.
void* (UNITY_INTERFACE_API * Allocate)(UnityAllocator * allocator, size_t size, size_t align, const char* file, int32_t line);
Parameter | Description |
---|---|
UnityAllocator * allocator | The allocator to use for allocation. |
size_t size | How much memory to allocate, in bytes. |
size_t align | The alignment of the memory address for the resulting pointer. |
const char* file | The path to the source file where the call to make this allocation came from. Use the predefined macro FILE here. |
int32_t line | The line number in the source file where the call to make this allocation came from. Use the predefined macro LINE here. |
Allocates a block of memory using an existing allocator. This method returns a pointer to the newly allocated memory.
void(UNITY_INTERFACE_API * Deallocate)(UnityAllocator * allocator, void* ptr, const char* file, int32_t line);
Parameter | Description |
---|---|
UnityAllocator * allocator | The allocator to use for deallocation. |
void* ptr | The pointer to the memory to be deallocated. |
const char* file | The path to the source file where the call to make this deallocation came from. Use the predefined macro FILE here. |
int32_t line | The line number in the source file where the call to make this deallocation came from. Use the predefined macro LINE here. |
Deallocates the memory that the specified pointer points to. This doesn’t set the pointer to NULL.
void* (UNITY_INTERFACE_API * Reallocate)(UnityAllocator * allocator, void* ptr, size_t size, size_t align, const char* file, int32_t line);
Parameter | Description |
---|---|
UnityAllocator * allocator | The allocator to use for the reallocation operation. |
void* ptr | The pointer to the memory to be deallocated. |
size_t size | How much memory to allocate, in bytes. |
size_t align | The alignment of the memory address for the resulting pointer. |
const char* file | The path to the source file where the call to make this reallocation came from. Use the predefined macro FILE here. |
int32_t line | The line number in the source file where the call to make this reallocation came from. Use the predefined macro LINE here. |
Reallocates an existing pointer to point to a different block of memory.
Below 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 NativePlugins - Plugin Backend Allocator
// All memory allocated here also goes under kMemNativePlugin
s_Alloc = s_MemoryManager->CreateAllocator("NativePlugins", "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__);
}
When you visit any website, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and change our default settings. However, blocking some types of cookies may impact your experience of the site and the services we are able to offer.
More information
These cookies enable the website to provide enhanced functionality and personalisation. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies then some or all of these services may not function properly.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance.
These cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less targeted advertising. Some 3rd party video providers do not allow video views without targeting cookies. If you are experiencing difficulty viewing a video, you will need to set your cookie preferences for targeting to yes if you wish to view videos from these providers. Unity does not control this.
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information.