기술 자료

Unity 엔진

Unity 엔진

IUnityMemoryManager API reference

네이티브 플러그인에서 메모리 관리자 API 사용합니다.
읽는 시간 3분최근 업데이트: 9일 전

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

CreateAllocator

선언

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

파라미터

파라미터

설명

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

설명

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

DestroyAllocator

선언

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

파라미터

파라미터

설명

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

설명

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

설명

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

Deallocate

선언

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

파라미터

파라미터

설명

UnityAllocator * allocator할당 해제에 사용할 할당자입니다.
void ptr*할당 해제할 메모리에 대한 포인터입니다.
const char 파일*이 할당 해제를 위한 호출이 발생한 소스 파일의 경로입니다. 여기서 사전 정의된 매크로 _파일_을 사용합니다.
int32_t 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 파일*이 재할당을 위한 호출이 발생한 소스 파일의 경로입니다. 여기서 사전 정의된 매크로 _파일_을 사용합니다.
int32_t 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) 반환; // Create an allocator. 이를 통해 스냅샷을 찍을 때 프로파일러에서 할당 루트를 볼 수 있습니다. Plug-ins-native 아래 - 플러그인 백엔드 할당자 // 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__);}

추가 리소스