6#include "HAL/CriticalSection.h"
7#include "HAL/MemoryBase.h"
8#include "HAL/UnrealMemory.h"
9#include "Misc/AssertionMacros.h"
10#include "Misc/ScopeLock.h"
16#if !defined(UE_USE_MALLOC_REPLAY_PROXY)
24
25
26
27class FMallocReplayProxy :
public FMalloc
37 HistoryCacheSize = 16384
44 const char* Operation;
56 FHistoryEntry HistoryCache[HistoryCacheSize];
59 int32 CurrentCacheIdx;
62 uint64 OperationNumber;
65 FCriticalSection HistoryLock;
71 void AddToHistory(
const char *Op,
void * PtrOut,
void * PtrIn, SIZE_T Size, SIZE_T Alignment)
73 FScopeLock Lock(&HistoryLock);
75 HistoryCache[CurrentCacheIdx].Operation = Op;
76 HistoryCache[CurrentCacheIdx].PointerOut = PtrOut;
77 HistoryCache[CurrentCacheIdx].PointerIn = PtrIn;
78 HistoryCache[CurrentCacheIdx].Size = Size;
79 HistoryCache[CurrentCacheIdx].Alignment = Alignment;
82 if (CurrentCacheIdx > HistoryCacheSize - 1)
89 void DumpHistoryToDisk();
93 explicit FMallocReplayProxy(FMalloc* InMalloc);
95 virtual ~FMallocReplayProxy();
97 virtual void InitializeStatsMetadata() override;
99 virtual void* Malloc(SIZE_T Size, uint32 Alignment) override;
101 virtual void* Realloc(
void* Ptr, SIZE_T NewSize, uint32 Alignment) override;
103 virtual void Free(
void* Ptr) override;
105 virtual SIZE_T QuantizeSize(SIZE_T Count, uint32 Alignment) override;
107 virtual void UpdateStats() override;
109 virtual void GetAllocatorStats(FGenericMemoryStats& out_Stats) override;
111 virtual void DumpAllocatorStats(
class FOutputDevice& Ar) override;
113 virtual bool IsInternallyThreadSafe()
const override;
115 virtual bool ValidateHeap() override;
117 virtual bool Exec(UWorld* InWorld,
const TCHAR* Cmd, FOutputDevice& Ar) override;
119 virtual bool GetAllocationSize(
void *Original, SIZE_T &SizeOut) override;
121 virtual const TCHAR* GetDescriptiveName() override;
123 virtual void Trim(
bool bTrimThreadCaches) override;
125 virtual void SetupTLSCachesOnCurrentThread() override;
127 virtual void ClearAndDisableTLSCachesOnCurrentThread() override;
#define UE_BUILD_SHIPPING
#define UE_USE_MALLOC_REPLAY_PROXY