기술 자료

Unity Engine

Unity Engine

IUnityMemoryManager API 레퍼런스

Use the memory manager API in native plug-ins.
읽는 시간 3분최근 업데이트: 한 달 전

이 페이지는
IUnityMemoryManager
인터페이스에 대한 API 레퍼런스를 제공합니다.

CreateAllocator

선언

UnityAllocator* (UNITY_INTERFACE_API * CreateAllocator)(const char* areaName, const char* objectName);

파라미터

파라미터

설명

const char areaName*이 할당자의 광범위한 카테고리의 이름입니다.
const char objectName*이 특정 할당자의 이름입니다.

설명

메모리 블록을 할당할 수 있는 새 할당자 오브젝트를 생성합니다.

DestroyAllocator

선언

void(UNITY_INTERFACE_API * DestroyAllocator)(UnityAllocator * allocator);

파라미터

파라미터

설명

UnityAllocator * allocator삭제할 할당자입니다.

설명

기존 할당자 오브젝트를 삭제합니다.

Allocate

선언

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*이 할당을 위한 호출이 발생한 소스 파일의 경로입니다. 여기서 사전 정의된 macro _FILE_을 사용합니다.
int32_t line이 할당을 위한 호출이 발생한 소스 파일의 줄 번호입니다. 여기서 사전 정의된 macro _LINE_을 사용합니다.

설명

기존 할당자를 사용하여 메모리 블록을 할당합니다. 이 메서드는 새로 할당된 메모리에 대한 포인터를 반환합니다.

Deallocate

선언

void(UNITY_INTERFACE_API * Deallocate)(UnityAllocator * allocator, void* ptr, const char* file, int32_t line);

파라미터

파라미터

설명

UnityAllocator * allocator할당 해제에 사용할 할당자입니다.
void ptr*할당 해제할 메모리에 대한 포인터입니다.
const char file*이 할당 해제를 위한 호출이 발생한 소스 파일의 경로입니다. 여기서 사전 정의된 macro _FILE_을 사용합니다.
int32_t line이 할당 해제를 위한 호출이 발생한 소스 파일 내의 줄 번호입니다. 여기서 사전 정의된 macro _LINE_을 사용합니다.

설명

지정된 포인터가 가리키는 메모리를 할당 해제합니다. 이렇게 해도 포인터가 NULL로 설정되지 않습니다.

Reallocate

선언

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*이 재할당을 위한 호출이 발생한 소스 파일의 경로입니다. 여기서 사전 정의된 macro _FILE_을 사용합니다.
int32_t line이 재할당을 위한 호출이 발생한 소스 파일 내의 줄 번호입니다. 여기서 사전 정의된 macro _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 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__);}

추가 리소스