このページは IUnityMemoryManager
インターフェースの API リファレンスを提供します。
UnityAllocator* (UNITY_INTERFACE_API * CreateAllocator)(const char* areaName, const char* objectName);
パラメーター | 説明 |
---|---|
const char* areaName | このアロケーターの大きなカテゴリの名前です。 |
const char* objectName | この特定のアロケーターの名前です。 |
メモリブロックを割り当てることができる Allocator オブジェクトを新しく作成します。
void(UNITY_INTERFACE_API * DestroyAllocator)(UnityAllocator * allocator);
パラメーター | 説明 |
---|---|
UnityAllocator * allocator | 削除するアロケーターです。 |
既存の Allocator オブジェクトを削除します。
void* (UNITY_INTERFACE_API * Allocate)(UnityAllocator * allocator, size_t size, size_t align, const char* file, int32_t line);
パラメーター | 説明 |
---|---|
UnityAllocator * allocator | 割り当てに使用するアロケーターです。 |
size_t size | 割り当てるメモリの量をバイト数で表します。 |
size_t align | 結果のポインターのメモリアドレスの整列です。 |
const char* file | この割り当てを行う呼び出しの行われたソースファイルへのパスです。ここでは定義済みマクロ FILE を使用します。 |
int32_t line | この割り当てを行う呼び出しの行われたソースファイル内の行番号です。ここでは定義済みマクロ LINE を使用します。 |
既存のアロケーターを使用してメモリのブロックを割り当てます。このメソッドは、新しく割り当てられたメモリへのポインターを返します。
void(UNITY_INTERFACE_API * Deallocate)(UnityAllocator * allocator, void* ptr, const char* file, int32_t line);
パラメーター | 説明 |
---|---|
UnityAllocator * allocator | 割り当て解除に使用するアロケーターです。 |
void* ptr | 割り当て解除されるメモリへのポインターです。 |
const char* file | この割り当て解除を行う呼び出しが行われたソースファイルへのパスです。ここでは定義済みマクロ FILE を使用します。 |
int32_t line | この割り当て解除を行う呼び出しが行われたソースファイル内の行番号です。ここでは定義済みマクロ LINE を使用します。 |
指定されたポインターが指すメモリの割り当てを解除します。これは、ポインターを NULL には設定しません。
void* (UNITY_INTERFACE_API * Reallocate)(UnityAllocator * allocator, void* ptr, size_t size, size_t align, const char* file, int32_t line);
パラメーター | 説明 |
---|---|
UnityAllocator * allocator | 再割り当て操作に使用するアロケーターです。 |
void* ptr | 割り当て解除されるメモリへのポインターです。 |
size_t size | 割り当てるメモリの量をバイト数で表します。 |
size_t align | 結果のポインターのメモリアドレスの整列です。 |
const char* file | この再割り当てを行う呼び出しが行われたソースファイルへのパスです。ここでは定義済みマクロ FILE を使用します。 |
int32_t line | この再割り当てを行う呼び出しが行われたソースファイル内の行番号です。ここでは定義済みマクロ LINE を使用する。 |
既存のポインターを、別のメモリブロックを指すように再割り当てします。
以下は IUnityMemoryManager
インターフェースの実装例です。
# 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**);
}
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.