15 enum { MEM_PreTag = 0xf0ed1cee };
16 enum { MEM_PostTag = 0xdeadf00f };
17 enum { MEM_Tag = 0xfe };
18 enum { MEM_WipeTag = 0xcd };
21 enum { ALLOCATION_ALIGNMENT = 16 };
24 enum { MEM_SizeMax = 128 };
25 enum { MEM_Recent = 5000 };
26 enum { MEM_AgeMax = 80 };
27 enum { MEM_AgeSlice = 100 };
40 FMemDebug* GFirstDebug;
43 SIZE_T TotalAllocationSize;
47 static constexpr uint32 AllocatorOverhead =
sizeof(FMemDebug) +
sizeof(FMemDebug*) +
sizeof(
int32) + ALLOCATION_ALIGNMENT +
sizeof(
int32);
52 : GFirstDebug( nullptr )
53 , TotalAllocationSize( 0 )
62 check(Alignment <= ALLOCATION_ALIGNMENT &&
"Alignment currently unsupported in this allocator");
63 FMemDebug* Ptr = (FMemDebug*)malloc( AllocatorOverhead +
Size );
65 uint8* AlignedPtr =
Align( (
uint8*) Ptr +
sizeof(FMemDebug) +
sizeof(FMemDebug*) +
sizeof(
int32), ALLOCATION_ALIGNMENT );
69 Ptr->Next = GFirstDebug;
70 Ptr->PrevLink = &GFirstDebug;
71 Ptr->PreTag = (
int32*) (AlignedPtr -
sizeof(
int32));
72 *Ptr->PreTag = MEM_PreTag;
73 *((FMemDebug**)(AlignedPtr -
sizeof(
int32) -
sizeof(FMemDebug*))) = Ptr;
79 GFirstDebug->PrevLink = &Ptr->Next;
82 TotalAllocationSize +=
Size;
83 TotalWasteSize += AllocatorOverhead;
93 if(
InPtr && NewSize )
95 FMemDebug* Ptr = *((FMemDebug**)((
uint8*)
InPtr -
sizeof(
int32) -
sizeof(FMemDebug*)));
97 void* Result =
Malloc( NewSize, Alignment );
102 else if(
InPtr ==
nullptr )
104 return Malloc( NewSize, Alignment );
123 FMemDebug* Ptr = *((FMemDebug**)((
uint8*)
InPtr -
sizeof(
int32) -
sizeof(FMemDebug*)));
129 TotalAllocationSize -= Ptr->Size;
130 TotalWasteSize -= AllocatorOverhead;
138 *Ptr->PrevLink = Ptr->Next;
141 Ptr->Next->PrevLink = Ptr->PrevLink;
162 const FMemDebug* Ptr = *((FMemDebug**)((
uint8*)
Original -
sizeof(
int32) -
sizeof(FMemDebug*)));
176 Ar.
Logf(
TEXT(
"Total Allocation Size: %u" ), TotalAllocationSize );
177 Ar.
Logf(
TEXT(
"Total Waste Size: %u" ), TotalWasteSize );
183 Ar.
Logf(
TEXT(
"Unfreed memory:" ) );
184 for( FMemDebug* Ptr = GFirstDebug; Ptr; Ptr = Ptr->Next )
190 Ar.
Logf(
TEXT(
"End of list: %i Bytes still allocated" ),
Count );
191 Ar.
Logf(
TEXT(
" %i Chunks allocated" ), Chunks );
199 for( FMemDebug**
Link = &GFirstDebug; *
Link;
Link=&(*Link)->Next )
constexpr T Align(T Val, uint64 Alignment)
Definition AlignmentTemplates.h:18
#define check(expr)
Definition AssertionMacros.h:314
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
uint32 Size
Definition VulkanMemory.cpp:4034
Definition MallocDebug.h:13
FMallocDebug()
Definition MallocDebug.h:51
virtual void * Malloc(SIZE_T Size, uint32 Alignment) override
Definition MallocDebug.h:60
virtual bool ValidateHeap() override
Definition MallocDebug.h:197
virtual bool GetAllocationSize(void *Original, SIZE_T &SizeOut) override
Definition MallocDebug.h:154
virtual void * Realloc(void *InPtr, SIZE_T NewSize, uint32 Alignment) override
Definition MallocDebug.h:91
virtual bool Exec(UWorld *InWorld, const TCHAR *Cmd, FOutputDevice &Ar) override
Definition MallocDebug.h:214
virtual void Free(void *InPtr) override
Definition MallocDebug.h:116
virtual void DumpAllocatorStats(FOutputDevice &Ar) override
Definition MallocDebug.h:174
virtual const TCHAR * GetDescriptiveName() override
Definition MallocDebug.h:219
Definition MemoryBase.h:99
Definition OutputDevice.h:133
void Logf(const FmtType &Fmt)
Definition OutputDevice.h:234
static UE_FORCEINLINE_HINT void * Memcpy(void *Dest, const void *Src, SIZE_T Count)
Definition UnrealMemory.h:160
static UE_FORCEINLINE_HINT void * Memset(void *Dest, uint8 Char, SIZE_T Count)
Definition UnrealMemory.h:119