void FStatsMallocProfilerProxy::TrackRealloc( void* OldPtr, void* NewPtr, int64 NewSize, int32 SequenceTag )
{
	if (bEnabled)
	{
		if (OldPtr != nullptr && NewSize > 0)
		{
			FThreadStats* ThreadStats = FThreadStats::GetThreadStats();
			if (ThreadStats->MemoryMessageScope == 0)
			{
				// 64 bytes per reallocation. 80 for Free/Alloc
				ThreadStats->AddMemoryMessage( GET_STATFNAME( STAT_Memory_FreePtr ), (uint64)(UPTRINT)OldPtr | (uint64)EMemoryOperation::Realloc );
				ThreadStats->AddMemoryMessage( GET_STATFNAME( STAT_Memory_AllocPtr ), (uint64)(UPTRINT)NewPtr | (uint64)EMemoryOperation::Realloc );
				ThreadStats->AddMemoryMessage( GET_STATFNAME( STAT_Memory_AllocSize ), NewSize );
				ThreadStats->AddMemoryMessage( GET_STATFNAME( STAT_Memory_OperationSequenceTag ), (int64)SequenceTag );
				ReallocPtrCalls.Increment();
			}
		}
		else if (OldPtr == nullptr)
		{
#if !PLATFORM_XBOXONE
			TrackAlloc( NewPtr, NewSize, SequenceTag );
#endif
		}
		else
		{
			TrackFree( OldPtr, SequenceTag );
		}
	}
}
void* FStatsMallocProfilerProxy::Malloc( SIZE_T Size, uint32 Alignment )
{
	void* Ptr = UsedMalloc->Malloc( Size, Alignment );
	const int32 SequenceTag = MemorySequenceTag.Increment();
	// We lose the Size's precision, but don't worry about it.
	TrackAlloc( Ptr, (int64)Size, SequenceTag );
	return Ptr;
}
void* FStatsMallocProfilerProxy::Realloc( void* OldPtr, SIZE_T NewSize, uint32 Alignment )
{
	const int32 FreeSequenceTag = MemorySequenceTag.Increment();
	TrackFree( OldPtr, FreeSequenceTag );

	const int32 AllocSequenceTag = MemorySequenceTag.Increment();
	void* NewPtr = UsedMalloc->Realloc( OldPtr, NewSize, Alignment );
	TrackAlloc( NewPtr, (int64)NewSize, AllocSequenceTag );
	return NewPtr;
}