Navigation
API > API/Runtime > API/Runtime/Core > API/Runtime/Core/Misc
Inheritance Hierarchy
- FAllocatorModifier
- TRangeAllocator
References
| Module | Core |
| Header | /Engine/Source/Runtime/Core/Public/Misc/RangeAllocator.h |
| Include | #include "Misc/RangeAllocator.h" |
Syntax
template<typename FAllocatorModifier>
class TRangeAllocator : public FAllocatorModifier
Remarks
This allocator has a list of chunks (fixed size committed memory regions) and each chunk keeps a list of free ranges. Allocations are served by finding a large enough free range and sub-allocating from it. Freed allocations become free ranges and are combined with adjacent free ranges if possible. It is meant to be a faster version of TGenericGrowableAllocator but imposes some restrictions on size and alignment. The restrictions are that alignments must be power of two, ChunkSize must be a multiple of MinAlignment, and the quotient of dividing ChunkSize by MinAlignment must be representable by a 16-bit unsigned integer. Note that allocations smaller than MinAlignment will be padded to MinAlignment and it cannot allocate larger than ChunkSize. It is advised to use multiple instances of range allocators where each handles a range of allocation sizes (e.g. three allocators for allocations smaller than 1 KB, between 1 KB and 128 KB, and between 128 KB and 1 MB, respectively). Doing so usually lead to better performance and less fragmentation.
To use this allocator, implement your own FAllocatorModifier to customize behaviors and handle platform specific stuff. Your implementation should at minimum contain the members listed below.
class FAllocatorModifier { static constexpr uint32 ChunkSize = <...>; static constexpr uint32 MinAlignment = <...>;
// The type of "pointer" returned by this allocator typedef <...> FPointerType; typedef <...> FConstPointerType;
// Contains information needed to represent a chunk struct FChunkModifier { // You may allocate the actual backing memory here and store its base address FChunkModifier(const FAllocatorModifier& Allocator);
// Custom cleanup such as releasing backing memory ~FChunkModifier();
// Reinterpret the offset in chunk such as adding it to a base address SIZE_T AdjustAllocation(SIZE_T OffsetInChunk) [const];
// Whether this chunk is valid bool IsValid() const;
// Whether Addr is in this chunk bool Contains(FConstPointerType Addr) const; };
// Contains information needed to represent an allocation struct FAllocInfoModifier { // Initialize custom members. Ptr is the output of AdjustAllocation void InitCustomInfo(const FChunkModifier& Chunk, SIZE_T Ptr); };
// Convert AdjustAllocation output to the pointer type such as a simple type cast static FPointerType MakePointer(SIZE_T Ptr);
// Custom assert implementation static void Check(bool bOk); };
Once the modifier is implemented, feed it to TRangeAllocator as a template argument. You may derive from TRangeAllocator
Variables
| Type | Name | Description | |
|---|---|---|---|
| TArray< FChunk > | Chunks | ||
| FCriticalSection | CS | ||
| TArray< FFreeChunkInfo > | FreeChunkInfos | ||
| int32 | FreeChunkSlotHead | ||
| const uint16 | MinAllocSize | ||
| SIZE_T | SizeTotal | ||
| SIZE_T | SizeUsed |
Constructors
| Type | Name | Description | |
|---|---|---|---|
TRangeAllocator
(
uint32 InMinAllocSize, |
Functions
| Type | Name | Description | |
|---|---|---|---|
| FPointerType | Alloc
(
uint32 Size, |
||
| bool | Contains
(
FConstPointerType Addr |
||
| void | Free
(
const FAllocInfo& AllocInfo |
||
| void | |||
| void | RemoveFreeChunkInfo
(
int32 InfoIndex |
Classes
| Type | Name | Description | |
|---|---|---|---|
| FAllocInfo | |||
| FChunk | |||
| FFreeChunkInfo |
Typedefs
| Name | Description |
|---|---|
| FAllocInfoModifier | |
| FChunkModifier | |
| FConstPointerType | |
| FPointerType | |
| FRangeAllocator |