---
title: IUnityMemoryManager API reference
product: Unity Editor
version: '6000.0'
latest_version: '7000.0'
status: This page documents version 6000.0. The latest version is 7000.0.
canonical: https://docs.unity.com/ja-jp/engine/6000.0/manual/scripting/compilation-and-code-reload/plug-ins/native-plugin-interface/low-level-native-plugin-memory-manager-api-reference
latest_url: https://docs.unity.com/ja-jp/engine/7000.0/manual/scripting/compilation-and-code-reload/plug-ins/native-plugin-interface/low-level-native-plugin-memory-manager-api-reference.md
generated_at: 2026-11-16T09:54:04.130Z
locale: ja-jp
---

# IUnityMemoryManager API reference

> ネイティブ プラグインで Memory Manager API を使用します。

このページでは、`IUnityMemoryManager` インターフェースの API リファレンスを提供します。

## CreateAllocator##createallocator

### 宣言##declaration

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

### パラメーター##parameters

| **パラメーター**                  | **説明**               |
| --------------------------- | -------------------- |
| **const char* areaName*\*   | このアロケーターの幅広いカテゴリの名前。 |
| **const char* objectName*\* | この特定のアロケーターの名前。      |

### 説明##description

メモリブロックを割り当てることができる新しいアロケーターオブジェクトを作成します。

## DestroyAllocator##destroyallocator

### 宣言##declaration

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

### パラメーター##parameters

| **パラメーター**                      | **説明**      |
| ------------------------------- | ----------- |
| **UnityAllocator \* allocator** | 削除するアロケーター。 |

### 説明##description

既存のアロケーターオブジェクトを削除します。

## 割り当て##allocate

### 宣言##declaration

`void* (UNITY_INTERFACE_API * Allocate)(UnityAllocator * allocator, size_t size, size_t align, const char* file, int32_t line);`

### パラメーター##parameters

| **パラメーター**                      | **説明**                                                  |
| ------------------------------- | ------------------------------------------------------- |
| **UnityAllocator \* allocator** | アロケーションに使用するアロケーター。                                     |
| **size\_t size**                | 割り当てるメモリ量 (バイト単位)。                                      |
| **size\_t align**               | 結果ポインタのメモリアドレスの整列                                       |
| **const char* file*\*           | このアロケーションを行うコールのソース ファイルへのパス。ここで定義済みマクロ *FILE* を使用します。  |
| **int32\_t line**               | このアロケーションを行うコールのソース ファイル内の行番号。ここで定義済みマクロ *LINE* を使用します。 |

### 説明##description

既存のアロケーターを使用してメモリ ブロックを割り当てます。このメソッドは、新しく割り当てられたメモリへのポインターを返します。

## 割り当て解除##deallocate

### 宣言##declaration

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

### パラメーター##parameters

| **パラメーター**                      | **説明**                                                   |
| ------------------------------- | -------------------------------------------------------- |
| **UnityAllocator \* allocator** | 割り当て解除に使用するアロケーター。                                       |
| **void* ptr*\*                  | 割り当て解除するメモリへのポインター                                       |
| **const char* file*\*           | この割り当て解除を行うコール元のソースファイルへのパス。ここで定義済みマクロ *FILE* を使用します。    |
| **int32\_t line**               | この割り当て解除を行うコールが発生したソースファイルの行番号。ここで定義済みマクロ *LINE* を使用します。 |

### 説明##description

指定したポインターが指すメモリの割り当てを解除します。ポインタは null に設定されません。

## 再割り当て##reallocate

### 宣言##declaration

`void* (UNITY_INTERFACE_API * Reallocate)(UnityAllocator * allocator, void* ptr, size_t size, size_t align, const char* file, int32_t line);`

### パラメーター##parameters

| **パラメーター**                      | **説明**                                                  |
| ------------------------------- | ------------------------------------------------------- |
| **UnityAllocator \* allocator** | 再割り当て操作に使用するアロケーター。                                     |
| **void* ptr*\*                  | 割り当て解除するメモリへのポインター                                      |
| **size\_t size**                | 割り当てるメモリ量 (バイト単位)。                                      |
| **size\_t align**               | 結果ポインタのメモリアドレスの整列                                       |
| **const char* file*\*           | この再割り当てを行うコール元のソースファイルへのパス。ここで定義済みマクロ *FILE* を使用します。    |
| **int32\_t line**               | この再割り当てを行うコールが行われたソースファイルの行番号。ここで定義済みマクロ *LINE* を使用します。 |

### 説明##description

既存のポインターを別のメモリブロックを指すように再割り当てします。

## 実装例##implementation-example

以下は、`IUnityMemoryManager` インターフェースの実装例です。

```lang-cs
#include "IUnityInterface.h"
#include "IUnityMemoryManager.h"
#include <cstdint>

static IUnityMemoryManager* s_MemoryManager = NULL;
static UnityAllocator* s_Alloc = NULL;

extern "C" void Unity_インターフェース_エクスポート Unity_インターフェース_API UnityPluginLoad(IUnityInterfaces * unityInterfaces)
{
    s_MemoryManager = unityInterfaces->Get<IUnityMemoryManager>();
    if (s_MemoryManager  == NULL)
	return;

    // Create an 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

* [低レベルのネイティブプラグインレンダリング拡張](/engine/6000.0/manual/scripting/compilation-and-code-reload/plug-ins/native-plugin-interface/low-level-native-plugin-rendering-extensions.md)
* [低レベルのネイティブプラグインシェーダーコンパイラーアクセス](/engine/6000.0/manual/scripting/compilation-and-code-reload/plug-ins/native-plugin-interface/low-level-native-plugin-shader-compiler-access.md)
* [低レベルのネイティブプラグインメモリマネージャ API](/engine/6000.0/manual/scripting/compilation-and-code-reload/plug-ins/native-plugin-interface/low-level-native-plugin-memory-manager-api.md)
