24#define ALLOCATION_HISTOGRAM (!UE_BUILD_SHIPPING && !UE_BUILD_TEST) && 1
25#define ALLOCATION_HISTOGRAM_DETAILED (!UE_BUILD_SHIPPING && !UE_BUILD_TEST) && 0
176 for (FFreeEntry* Entry =
FreeList; Entry; Entry = Entry->Next)
195 bool bResult =
false;
196 for (FFreeEntry *Entry =
FreeList; Entry; Entry = Entry->Next)
198 if (Entry->CanFit(
Size, Alignment))
231 FFreeEntry* Prev =
NULL;
232 FFreeEntry* FindEntry =
NULL;
234 for (FFreeEntry* Entry =
FreeList; Entry; Entry = Entry->Next)
236 if (Entry->CanFit(AlignedSize, Alignment))
244 if (FindEntry !=
NULL)
264 Allocation->
Size = AlignedSize;
267#if !UE_BUILD_SHIPPING
303 FFreeEntry* Prev =
NULL;
305 while (Entry &&
Offset > Entry->Location)
312 if (Entry && (
Offset +
Size) == Entry->Location)
315 Entry->Location -=
uint32(AllocationSize);
316 Entry->BlockSize +=
uint32(AllocationSize);
319 if (Prev && (Prev->Location + Prev->BlockSize) == Entry->Location)
321 Prev->BlockSize += Entry->BlockSize;
322 Prev->Next = Entry->Next;
334 if (Prev && (Prev->Location + Prev->BlockSize +
Padding) ==
Offset)
337 Prev->BlockSize +=
uint32(AllocationSize);
340 if (Entry && (Prev->Location + Prev->BlockSize) == Entry->Location)
342 Prev->BlockSize += Entry->BlockSize;
343 Prev->Next = Entry->Next;
389 Total += Entry->BlockSize;
445 check((UsedSize & (Alignment - 1)) == 0);
455 if (BlockSize - AllocationSize >=
MinSize)
458 Location +=
uint32(AllocationSize);
459 BlockSize -=
uint32(AllocationSize);
511template <
typename ChunkAllocatorType,
typename GrowableAllocationBaseType>
533 CreateAllocChunk(InitialSize);
549#if !UE_BUILD_SHIPPING
550 if (!Chunk->IsEmpty())
557 RemoveAllocChunk(Chunk);
566 Alignment = FPlatformMath::Max<uint32>(Alignment, SubAllocationAlignment);
584 for (
int32 ChunkIndex = 0; ChunkIndex < AllocChunks.
Num(); ChunkIndex++)
587 if (Chunk && Chunk->CanFitEntry(AlignedSize, Alignment))
613#if ALLOCATION_HISTOGRAM
614 TotalAllocationsHistogram.FindOrAdd(AlignedSize)++;
615 PeakAllocationsHistogram.FindOrAdd(AlignedSize)++;
618 AllocationInfo&
TypeAllocInfo = PerTypeAllocationInfo.FindOrAdd(Result->OwnerType);
622#if ALLOCATION_HISTOGRAM_DETAILED
623 TypeAllocInfo.AllocationHistogram.FindOrAdd(Result->Size).Allocations++;
628 if (OwnerTypeToStatIdMap)
648 for (
int32 ChunkIndex = 0; ChunkIndex < AllocChunks.
Num(); ChunkIndex++)
651 if (Chunk && Chunk->DoesChunkContainAllocation(
Memory))
653#if ALLOCATION_HISTOGRAM
654 PeakAllocationsHistogram[
Memory->Size]--;
661#if ALLOCATION_HISTOGRAM_DETAILED
667 if (OwnerTypeToStatIdMap)
677 if (Chunk->IsEmpty())
680 RemoveAllocChunk(Chunk);
701 for (
int32 ChunkIndex = 0; ChunkIndex < AllocChunks.
Num(); ChunkIndex++)
722 for (
int32 ChunkIndex = 0; ChunkIndex < AllocChunks.
Num(); ChunkIndex++)
725 if (Chunk && Chunk->DoesChunkContainAddress(Address))
745#if ALLOCATION_HISTOGRAM
747 for (
auto It = TotalAllocationsHistogram.CreateIterator(); It; ++It)
755 for (
int32 ChunkIndex = 0; ChunkIndex < AllocChunks.
Num(); ChunkIndex++)
761 Chunk->ShowFullAllocationList();
768#if ALLOCATION_HISTOGRAM
774 if (OwnerTypeToStatIdMap)
782#if ALLOCATION_HISTOGRAM_DETAILED
795 void UpdateMemoryStatMaxSizes()
822 UpdateMemoryStatMaxSizes();
849 UpdateMemoryStatMaxSizes();
857#if !UE_BUILD_SHIPPING
864 const uint32 SubAllocationAlignment;
870 uint64 TotalAllocationSize;
877 FName StatRegionName;
880 const FName* OwnerTypeToStatIdMap;
891#if ALLOCATION_HISTOGRAM
892 struct AllocFreeCounts
897 struct AllocationInfo
900#if ALLOCATION_HISTOGRAM_DETAILED
903 AllocFreeCounts Counts;
#define NULL
Definition oodle2base.h:134
constexpr T Align(T Val, uint64 Alignment)
Definition AlignmentTemplates.h:18
#define checkSlow(expr)
Definition AssertionMacros.h:332
#define check(expr)
Definition AssertionMacros.h:314
#define checkf(expr, format,...)
Definition AssertionMacros.h:315
@ INDEX_NONE
Definition CoreMiscDefines.h:150
#define DEC_MEMORY_STAT_BY_FName(Stat, Amount)
Definition Stats.h:720
#define INC_MEMORY_STAT_BY_FName(Stat, Amount)
Definition Stats.h:716
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE::FPlatformRecursiveMutex FCriticalSection
Definition CriticalSection.h:53
#define UE_LOG(CategoryName, Verbosity, Format,...)
Definition LogMacros.h:270
#define LLM_IF_ENABLED(...)
Definition LowLevelMemTracker.h:1093
void MemoryTrace_Free(uint64 Address, HeapId RootHeap=EMemoryTraceRootHeap::SystemMemory, uint32 ExternalCallstackId=0)
Definition MemoryTrace.h:200
@ SystemMemory
Definition MemoryTrace.h:35
void MemoryTrace_Alloc(uint64 Address, uint64 Size, uint32 Alignment, HeapId RootHeap=EMemoryTraceRootHeap::SystemMemory, uint32 ExternalCallstackId=0)
Definition MemoryTrace.h:199
#define Split(a, ahi, alo)
Definition Predicates.inl:204
uint32 Offset
Definition VulkanMemory.cpp:4033
uint32 Size
Definition VulkanMemory.cpp:4034
Definition GenericGrowableAllocator.h:39
virtual uint64 GetWasteApproximation()
Definition GenericGrowableAllocator.h:54
uint64 CurrentAllocs
Definition GenericGrowableAllocator.h:69
virtual ~FGrowableMallocBase()
Definition GenericGrowableAllocator.h:48
uint64 TotalWaste
Definition GenericGrowableAllocator.h:66
FGrowableMallocBase()
Definition GenericGrowableAllocator.h:42
uint64 TotalAllocated
Definition GenericGrowableAllocator.h:63
uint64 TotalAllocs
Definition GenericGrowableAllocator.h:72
Definition GenericGrowableAllocator.h:78
FFreeEntry * FreeList
Definition GenericGrowableAllocator.h:499
FGrowableMallocChunk(uint64 InSize, uint32 Type, FCriticalSection *InCriticalSection)
Definition GenericGrowableAllocator.h:133
void Initialize()
Definition GenericGrowableAllocator.h:142
bool IsEmpty()
Definition GenericGrowableAllocator.h:209
virtual void DestroyInternalMemory()=0
virtual bool DoesChunkContainAllocation(const FGrowableAllocationBase *Allocation)=0
uint64 HeapSize
Definition GenericGrowableAllocator.h:490
uint32 MemoryType
Definition GenericGrowableAllocator.h:487
void Destroy()
Definition GenericGrowableAllocator.h:158
FGrowableAllocationBase * Malloc(uint32 Size, uint32 Alignment, uint32 MinAllocationSize, int32 OwnerType)
Definition GenericGrowableAllocator.h:214
uint64 UsedMemorySize
Definition GenericGrowableAllocator.h:493
bool Free(FGrowableAllocationBase *Memory)
Definition GenericGrowableAllocator.h:283
static const uint32 MaxFreeEntrySizeDirty
Definition GenericGrowableAllocator.h:504
virtual void * GetAddressForTracking(uint32 Offset)=0
void ShowFullAllocationList()
Definition GenericGrowableAllocator.h:365
uint32 MaxFreeEntrySize
Definition GenericGrowableAllocator.h:496
virtual void DestroyAllocationStruct(FGrowableAllocationBase *Allocation)
Definition GenericGrowableAllocator.h:108
virtual ~FGrowableMallocChunk()
Definition GenericGrowableAllocator.h:154
bool CanFitEntry(uint32 Size, uint32 Alignment)
Definition GenericGrowableAllocator.h:170
void GetAllocationInfo(uint64 &Used, uint64 &Free)
Definition GenericGrowableAllocator.h:358
virtual FGrowableAllocationBase * CreateAllocationStruct()=0
FCriticalSection * CriticalSection
Definition GenericGrowableAllocator.h:502
virtual uint64 CreateInternalMemory(uint64 Size)=0
virtual void InitializeAllocationStruct(FGrowableAllocationBase *Allocation)=0
virtual bool DoesChunkContainAddress(const void *Address)=0
Definition NameTypes.h:617
CORE_API FString ToString() const
Definition UnrealNames.cpp:3537
Definition ScopeLock.h:141
UE_REWRITE SizeType Num() const
Definition Array.h:1144
UE_NODEBUG UE_FORCEINLINE_HINT SizeType Add(ElementType &&Item)
Definition Array.h:2696
UE_NODEBUG UE_FORCEINLINE_HINT bool IsValidIndex(SizeType Index) const
Definition Array.h:1122
UE_NODEBUG UE_FORCEINLINE_HINT bool Find(const ElementType &Item, SizeType &Index) const
Definition Array.h:1302
Definition GenericGrowableAllocator.h:513
TGenericGrowableAllocator(uint64 InitialSize, uint32 InType, uint32 InSubAllocationAlignment, FName InStatRegionName, const FName *InOwnerTypeToStatIdMap, void *InUserData)
Definition GenericGrowableAllocator.h:523
virtual ~TGenericGrowableAllocator()
Definition GenericGrowableAllocator.h:541
void DumpMemoryInfo()
Definition GenericGrowableAllocator.h:766
void ShowAllocationInfo()
Definition GenericGrowableAllocator.h:733
void ShowFullAllocationInfo()
Definition GenericGrowableAllocator.h:740
bool DoesAllocatorContainAddress(const void *Address)
Definition GenericGrowableAllocator.h:716
GrowableAllocationBaseType * Malloc(uint32 Size, uint32 Alignment, int32 OwnerType)
Definition GenericGrowableAllocator.h:563
bool Free(GrowableAllocationBaseType *Memory)
Definition GenericGrowableAllocator.h:637
void GetAllocationInfo(uint32 &Chunks, uint64 &Used, uint64 &Free)
Definition GenericGrowableAllocator.h:694
Definition UnrealString.h.inl:34
U16 Index
Definition radfft.cpp:71
Definition GenericGrowableAllocator.h:28
uint32 Padding
Definition GenericGrowableAllocator.h:31
uint32 Offset
Definition GenericGrowableAllocator.h:30
uint64 Size
Definition GenericGrowableAllocator.h:29
uint32 OwnerType
Definition GenericGrowableAllocator.h:33