Version: 2023.2
언어: 한국어
Native memory
Bucket allocator

Dynamic heap allocator

The dynamic heap allocator is the main heap allocator. It applies the algorithm Two Level Segregated Fit (TLSF) to blocks of memory.

Each platform has a default block size, which you can customize. An allocation must be smaller than half a block. An allocation of half a block or more is too large for the dynamic heap allocator and in such cases Unity uses the virtual memory API to make the allocation instead.

동적 힙 할당자에 대한 메모리 사용량 보고서의 예는 다음과 같습니다.

[ALLOC_DEFAULT_MAIN]
Peak usage frame count: [16.0 MB-32.0 MB]: 497 frames, [32.0 MB-64.0 MB]: 1 frames
Requested Block Size 16.0 MB
Peak Block count 2
Peak Allocated memory 54.2 MB
Peak Large allocation bytes 40.2 MB

이 예에서 TLSF 블록 크기는 16MB로 설정되고 Unity는 두 개의 블록을 할당했습니다. 할당자의 최대 사용량은 54.2MB였습니다. 52.4MB 중 40.2MB는 TLSF 블록에 할당되지 않고 가상 메모리로 대체되었습니다. 대부분의 프레임에는 16–32MB의 메모리가 할당된 반면 한 프레임(로딩 프레임으로 추정)은 최대 32–64MB의 메모리를 사용했습니다.

블록 크기를 늘리면 큰 할당이 가상 메모리로 대체되지 않고 동적 힙에 유지됩니다. 그러나 블록 크기가 크면 블록이 완전히 사용되지 않을 수 있으므로 메모리 낭비로 이어질 수 있습니다.

Tip: The type tree and file cache allocators use dynamic heap allocation. To save the memory blocks they would otherwise use under this algorithm, you can set the type tree block size and file cache block size to 0. Allocations that would have used typetree and cache will then fall back to the main allocator instead. Note that this comes with the risk of increased native memory fragmentation. Refer to Customize allocators for how to set these block sizes.

Native memory
Bucket allocator