IUnityMemoryManager
メモリマネージャー API は、Unity のメモリ管理とメモリプロファイリングをネイティブプラグインで使用できるようにする C++ インターフェースです。
この API を使用すると、以下が行えます。
これらの機能によって、プラグインのメモリ割り当ての管理とプロファイリングが (C++ でこれと同等のメモリ管理メソッドを使用するよりも) 簡単に行えます。
このプラグイン API は IUnityMemoryManager インターフェースによって提供されます。このインターフェースは IUnityMemoryManager.h
ヘッダー内で宣言されます。この API の完全な参照は、このファイル内にあります。ヘッダーファイルを見つけるには、以下を参照してください。
<UnityInstallPath>\Editor\Data\PluginAPI
フォルダー内にこのヘッダーが保存されます。Contents\PluginAPI
内にあります。この API を効果的に使用するためには、以下の概念に関する理解が必要です。
プラグインのメモリ使用状況を追跡するには、Memory Profiler パッケージ を使用してスナップショットを撮り、All Of Memory タブ でスナップショットを開きます。IUnityMemoryManager
を使用してメモリを割り当てると、Memory Profiler に、プラグインのメモリ割り当てが (各アロケーターの作成時にアサインした領域とオブジェクトの名前の下に) 表示されます。
以下のスクリーンショットでは、Memory Profiler パッケージウィンドウに、IUnityMemoryManager
API でメモリを割り当てられたネイティブプラグインの、メモリ使用量が表示されています。この例では、areaName パラメーターを “MyNativePlugin”、objectName パラメーターを “MyPluginAllocator” として CreateAllocator メソッドが呼び出されています。詳細は CreateAllocator を参照してください。
詳細は Snapshots を参照してください。
この API を使用すると、ネイティブプラグインの開発時に Unity のメモリ管理システムが使用できるようになります。これには上述のとおり大きな利点がありますが、制限がないわけではありません。Unity のメモリ管理システムには以下の特徴があります。
ネイティブ C++ のメモリは管理されないため、アプリケーションに必要なメモリを全て把握しておく必要があります。これには、割り当てるメモリの量を適切に選択することや、不要になったメモリを確実に解放することが含まれます。
IUnityMemoryManager
API を使用する場合、割り当てのたびに仮想呼び出しが必要になるため、パフォーマンスへの影響があります。このパフォーマンスへの影響を最小限に抑えるには、この API を使用して、大きなメモリブロックを低い頻度で割り当てます。小さい頻繁な割り当てを処理するには、この API を使用して単一の大きなブロックを割り当てた上で、独自のコードを記述してこのブロック内のメモリを管理します。小さい頻繁な割り当てには、この API を使用しないでください。
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.