5#include "Containers/ContainerAllocationPolicies.h"
6#include "Containers/LockFreeFixedSizeAllocator.h"
9#include "HAL/MemoryBase.h"
10#include "HAL/PlatformCrt.h"
11#include "HAL/ThreadSafeCounter.h"
12#include "HAL/ThreadSingleton.h"
13#include "HAL/UnrealMemory.h"
14#include "Math/UnrealMathUtility.h"
15#include "Misc/AssertionMacros.h"
16#include "Misc/Build.h"
17#include "Misc/NoopCounter.h"
18#include "Templates/AlignmentTemplates.h"
19#include "Templates/UnrealTemplate.h"
73
74
75
76
86 *
this = MoveTemp(Other);
107 check((GIsCriticalError || !NumMarks));
113 return (uint8*)Alloc(AllocSize, FMath::Max(AllocSize >= 16 ? (size_t)16 : (size_t)8, Alignment));
122 check(!bShouldEnforceAllocMarks || NumMarks > 0);
125 uint8* Result = Align(
Top, Alignment );
126 uint8* NewTop = Result + AllocSize;
137 Result = Align(
Top, Alignment );
138 NewTop = Result + AllocSize;
195
196
197
231
232
237 return (T*)Mem.PushBytes( Count*
sizeof(T), Align );
241 uint8* Result = Mem.PushBytes( Count*
sizeof(T), Align );
242 FMemory::Memzero( Result, Count*
sizeof(T) );
247 uint8* Result = Mem.PushBytes( Count*
sizeof(T), Align );
248 FMemory::Memset( Result, 0xff, Count*
sizeof(T) );
254
255
261 const size_t SizeInBytes = Size * Count;
262 checkSlow(SizeInBytes <= (size_t)TNumericLimits<int32>::Max());
263 return Mem
.PushBytes( SizeInBytes
, __STDCPP_DEFAULT_NEW_ALIGNMENT__
);
268 const size_t SizeInBytes = Size * Count;
269 checkSlow(SizeInBytes <= (size_t)TNumericLimits<int32>::Max());
270 return Mem.PushBytes(SizeInBytes, (size_t)Align);
275 const size_t SizeInBytes = Size * Count;
276 checkSlow(SizeInBytes <= (size_t)TNumericLimits<int32>::Max());
277 uint8* Result = Mem
.PushBytes( SizeInBytes
, __STDCPP_DEFAULT_NEW_ALIGNMENT__
);
284 const size_t SizeInBytes = Size * Count;
285 checkSlow(SizeInBytes <= (size_t)TNumericLimits<int32>::Max());
286 uint8* Result = Mem.PushBytes(SizeInBytes, (size_t)Align);
293 const size_t SizeInBytes = Size * Count;
294 checkSlow(SizeInBytes <= (size_t)TNumericLimits<int32>::Max());
295 uint8* Result = Mem
.PushBytes( SizeInBytes
, __STDCPP_DEFAULT_NEW_ALIGNMENT__
);
302 const size_t SizeInBytes = Size * Count;
303 checkSlow(SizeInBytes <= (size_t)TNumericLimits<int32>::Max());
304 uint8* Result = Mem.PushBytes(SizeInBytes, (size_t)Align);
311 const size_t SizeInBytes = Size * Count;
312 checkSlow(SizeInBytes <= (size_t)TNumericLimits<int32>::Max());
313 return Mem
.PushBytes( SizeInBytes
, __STDCPP_DEFAULT_NEW_ALIGNMENT__
);
318 const size_t SizeInBytes = Size * Count;
319 checkSlow(SizeInBytes <= (size_t)TNumericLimits<int32>::Max());
320 return Mem.PushBytes(SizeInBytes, (size_t)Align);
325 const size_t SizeInBytes = Size * Count;
326 checkSlow(SizeInBytes <= (size_t)TNumericLimits<int32>::Max());
327 uint8* Result = Mem
.PushBytes(SizeInBytes
, __STDCPP_DEFAULT_NEW_ALIGNMENT__
);
334 const size_t SizeInBytes = Size * Count;
335 checkSlow(SizeInBytes <= (size_t)TNumericLimits<int32>::Max());
336 uint8* Result = Mem.PushBytes(SizeInBytes, (size_t)Align);
343 const size_t SizeInBytes = Size * Count;
344 checkSlow(SizeInBytes <= (size_t)TNumericLimits<int32>::Max());
345 uint8* Result = Mem
.PushBytes( SizeInBytes
, __STDCPP_DEFAULT_NEW_ALIGNMENT__
);
352 const size_t SizeInBytes = Size * Count;
353 checkSlow(SizeInBytes <= (size_t)TNumericLimits<int32>::Max());
354 uint8* Result = Mem.PushBytes(SizeInBytes, (size_t)Align);
365 using SizeType = int32;
370 template<
typename ElementType>
381
382
383
384
400 void ResizeAllocation(SizeType PreviousNumElements, SizeType NumElements,SIZE_T NumBytesPerElement)
456template <uint32 Alignment>
464
465
466
467
468
497 check(Mem.TopMark ==
this);
#define UE_BUILD_SHIPPING
T * NewOned(FMemStackBase &Mem, int32 Count=1, int32 Align=DEFAULT_ALIGNMENT)
T * New(FMemStackBase &Mem, int32 Count=1, int32 Align=DEFAULT_ALIGNMENT)
T * NewZeroed(FMemStackBase &Mem, int32 Count=1, int32 Align=DEFAULT_ALIGNMENT)
FMemMark * NextTopmostMark
FMemMark(FMemStackBase &InMem)
FMemStackBase::FTaggedMemory * SavedChunk
FORCEINLINE void * Alloc(size_t AllocSize, size_t Alignment)
bool ContainsPointer(const void *Pointer) const
bool bShouldEnforceAllocMarks
friend void * operator new(size_t Size, FMemStackBase &Mem, EMemZeroed Tag, int32 Count)
friend void * operator new[](size_t Size, std::align_val_t Align, FMemStackBase &Mem, EMemOned Tag, int32 Count)
FMemStackBase(const FMemStackBase &)=delete
FMemStackBase & operator=(FMemStackBase &&Other)
friend void * operator new(size_t Size, std::align_val_t Align, FMemStackBase &Mem, EMemOned Tag, int32 Count)
void AllocateNewChunk(int32 MinSize)
friend void * operator new(size_t Size, std::align_val_t Align, FMemStackBase &Mem, int32 Count)
friend void * operator new[](size_t Size, FMemStackBase &Mem, int32 Count)
FORCEINLINE bool IsEmpty() const
friend void * operator new(size_t Size, std::align_val_t Align, FMemStackBase &Mem, EMemZeroed Tag, int32 Count)
FMemStackBase(FMemStackBase &&Other)
friend void * operator new(size_t Size, FMemStackBase &Mem, EMemOned Tag, int32 Count)
friend void * operator new[](size_t Size, std::align_val_t Align, FMemStackBase &Mem, int32 Count)
int32 GetByteCount() const
FORCEINLINE uint8 * PushBytes(size_t AllocSize, size_t Alignment)
friend void * operator new(size_t Size, FMemStackBase &Mem, int32 Count)
friend void * operator new[](size_t Size, FMemStackBase &Mem, EMemZeroed Tag, int32 Count)
friend void * operator new[](size_t Size, std::align_val_t Align, FMemStackBase &Mem, EMemZeroed Tag, int32 Count)
FORCEINLINE int32 GetNumMarks()
friend void * operator new[](size_t Size, FMemStackBase &Mem, EMemOned Tag, int32 Count)
void FreeChunks(FTaggedMemory *NewTopChunk)
static FPageAllocator & Get()
static FPageAllocator * Instance
TPageAllocator TheAllocator
void LatchProtectedMode()
static FPageAllocator & Construct()
void FreeSmall(void *Mem)
FORCEINLINE void MoveToEmpty(ForElementType &Other)
FORCEINLINE SizeType CalculateSlackShrink(SizeType NumElements, SizeType NumAllocatedElements, SIZE_T NumBytesPerElement) const
FORCEINLINE SIZE_T GetAllocatedSize(SizeType NumAllocatedElements, SIZE_T NumBytesPerElement) const
FORCEINLINE SizeType CalculateSlackGrow(SizeType NumElements, SizeType NumAllocatedElements, SIZE_T NumBytesPerElement) const
FORCEINLINE ElementType * GetAllocation() const
FORCEINLINE SizeType CalculateSlackReserve(SizeType NumElements, SIZE_T NumBytesPerElement) const
void ResizeAllocation(SizeType PreviousNumElements, SizeType NumElements, SIZE_T NumBytesPerElement)
bool HasAllocation() const
SizeType GetInitialCapacity() const
ForElementType< FScriptContainerElement > ForAnyElementType
static FORCEINLINE void * Memzero(void *Dest, SIZE_T Count)
static FORCEINLINE void * Memset(void *Dest, uint8 Char, SIZE_T Count)