Version: 2023.2
言語: 日本語
ガベージコレクションのベストプラクティス
Dynamic heap allocator

Native memory

Note: The information on allocators in this section applies to native memory only and is not applicable to the managed heap, which is covered in the Managed memory section. This section assumes you have a general understanding of native memory management and allocators.

アプリケーションは、メモリアロケーターを使用して、パフォーマンスと使用可能なメモリ空間とのバランスを取ります。アプリケーションのメモリの空き容量が多い場合は、シーンやフレームをロードするにあたって、より高速でメモリ負荷の高いアロケーターが適しているかもしれません。しかし、アプリケーションのメモリが限られている場合は、低速なアロケーターを使用してでも、メモリを効率的に使用しなければなりません。様々なプロジェクトで最高のパフォーマンスを得るために、各アプリケーションのサイズと要件に合わせて、Unity のアロケーターをカスタマイズすることができます。

Unity has five allocator types. Each type has a different algorithm for fitting allocations into blocks of memory, and is therefore useful for different allocations. The important difference between allocations is usually persistence, or allocation lifespan, which determines where an allocation should go. For example, a long-lived (persistent) allocation goes to the heap and bucket allocators, while short-lived allocations go to the threadsafe linear and TLS allocators.

以下の表は、各アロケータータイプのアルゴリズムと用途をまとめたものです。

アロケータータイプ アルゴリズム 用途
Dynamic heap 2 レベル分離適合 (TLSF) • メイン (Main) アロケーター
• Gfx アロケーター
• Typetree アロケーター
• ファイルキャッシュ (File Cache) アロケーター
• プロファイラー (Profiler) アロケーター
• エディタープロファイラー (Editor Profiler) アロケーター (エディター上のみ)
Bucket 固定サイズのロックフリーアロケーター

• メイン (Main) アロケーター
• Gfx アロケーター
• Typetree アロケーター
• ファイルキャッシュ (File Cache) アロケーター
Dual thread サイズとスレッド ID に基づいて割り当てをリダイレクトする • メイン (Main) アロケーター
• Gfx アロケーター
• Typetree アロケーター
• ファイルキャッシュ (File Cache) アロケーター
Thread Local Storage (TLS) stack LIFO スタック 一時割り当て
Threadsafe linear ラウンドロビン FIFO ジョブへのデータ渡し用のバッファ

Note: The examples in this documentation use the memory usage reports that are written to the log when you close the Player or Editor if you have used the -log-memory-performance-stats command line argument. To find your log files, follow the instructions on the log files page.

ガベージコレクションのベストプラクティス
Dynamic heap allocator