145 ULANG_ASSERTF(NumElements < NumAllocatedElements,
"Invalid shrink parameters.");
149 const size_t CurrentSlackBytes = (NumAllocatedElements - NumElements)*BytesPerElement;
165 Retval = NumAllocatedElements;
173#if ULANG_AGGRESSIVE_MEMORY_SAVING
182 ULANG_ASSERTF(NumElements > NumAllocatedElements && NumElements > 0,
"Invalid grow parameters.");
185 if (NumAllocatedElements ||
size_t(NumElements) >
Grow)
210 ULANG_ASSERTF(NumElements > 0,
"Invalid reserve parameters.");
229template <
typename AllocatorType>
236template <
typename AllocatorType>
278 _RawAllocator.Deallocate(_Data);
282 _RawAllocator =
Other._RawAllocator;
283 Other._Data =
nullptr;
291 _RawAllocator.Deallocate(_Data);
304 return _RawAllocator;
316 if (_Data || NumElements)
319 size_t NumBytes = NumElements * NumBytesPerElement;
361 return NumAllocatedElements * NumBytesPerElement;
385 template<
typename ElementType>
401template<
class RawAllocatorType>
412template <u
int32_t NumInlineElements,
typename SecondaryAllocator = TDefaultElementAllocator<CHeapRawAllocator>,
typename... AllocatorArgsType>
422 template<
typename ElementType>
445 if (!
Other._SecondaryData.GetAllocation())
453 _SecondaryData.MoveToEmpty(
Other._SecondaryData);
458 return _SecondaryData.GetAllocation() ? _SecondaryData.GetAllocation() : GetInlineElements();
464 return _SecondaryData.GetRawAllocator();
470 if (
uint32_t(NumElements) <= NumInlineElements)
473 if (_SecondaryData.GetAllocation())
478 _SecondaryData.ResizeAllocation(0, 0, NumBytesPerElement);
483 if (!_SecondaryData.GetAllocation())
486 _SecondaryData.ResizeAllocation(0, NumElements, NumBytesPerElement);
502 return uint32_t(NumElements) <= NumInlineElements ?
504 _SecondaryData.CalculateSlackReserve(NumElements, NumBytesPerElement);
509 return uint32_t(NumElements) <= NumInlineElements ?
511 _SecondaryData.CalculateSlackShrink(NumElements, NumAllocatedElements, NumBytesPerElement);
516 return uint32_t(NumElements) <= NumInlineElements ?
518 _SecondaryData.CalculateSlackGrow(NumElements, NumAllocatedElements, NumBytesPerElement);
523 if (
uint32_t(NumAllocatedElements) > NumInlineElements)
525 return _SecondaryData.GetAllocatedSize(NumAllocatedElements, NumBytesPerElement);
532 return _SecondaryData.HasAllocation();
537 return NumInlineElements;
551 ElementType* GetInlineElements()
const
553 return (ElementType*)InlineData;
560template <u
int32_t NumInlineElements,
typename SecondaryAllocator>
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define ULANG_FORCEINLINE
Definition Common.h:188
#define ULANG_ASSERTF(expr, format,...)
Definition Common.h:290
Definition Allocator.h:35
ULANG_FORCEINLINE void * Reallocate(void *Memory, size_t NumBytes) const
Definition Allocator.h:46
CAllocatorInstance(FAllocate Allocate, FReallocate Reallocate, FDeallocate Deallocate)
Use the memory address of this object to seed the observer id generator.
Definition Allocator.h:42
void *(*)(const CAllocatorInstance *, size_t) FAllocate
Definition Allocator.h:37
ULANG_FORCEINLINE void * Allocate(size_t NumBytes) const
Definition Allocator.h:45
void *(*)(const CAllocatorInstance *, void *, size_t) FReallocate
Definition Allocator.h:38
ULANG_FORCEINLINE void Deallocate(void *Memory) const
Definition Allocator.h:47
ULANG_FORCEINLINE EObserverId GenerateObserverId()
Definition Allocator.h:49
void(*)(const CAllocatorInstance *, void *) FDeallocate
Definition Allocator.h:39
Raw memory allocator that allocates memory from the global heap.
Definition Allocator.h:64
static ULANG_FORCEINLINE void Deallocate(void *Memory)
Definition Allocator.h:71
ULANG_FORCEINLINE CHeapRawAllocator(EDefaultInit)
Definition Allocator.h:67
bool operator!=(const CHeapRawAllocator &Other) const
Definition Allocator.h:87
static ULANG_FORCEINLINE void * Reallocate(void *Memory, size_t NumBytes)
Definition Allocator.h:70
ULANG_FORCEINLINE CHeapRawAllocator()
Definition Allocator.h:66
static ULANG_FORCEINLINE EObserverId GenerateObserverId()
Definition Allocator.h:73
static ULANG_FORCEINLINE void * Allocate(size_t NumBytes)
Definition Allocator.h:69
bool operator==(const CHeapRawAllocator &Other) const
Any instance of this allocator is as good as any other.
Definition Allocator.h:86
Raw memory allocator that keeps a pointer to an allocator instance which is used for allocation.
Definition Allocator.h:92
ULANG_FORCEINLINE CInstancedRawAllocator(EDefaultInit)
Definition Allocator.h:95
ULANG_FORCEINLINE void * Reallocate(void *Memory, size_t NumBytes)
Definition Allocator.h:98
ULANG_FORCEINLINE CInstancedRawAllocator(CAllocatorInstance *AllocatorInstance)
Definition Allocator.h:94
ULANG_FORCEINLINE void Deallocate(void *Memory) const
Definition Allocator.h:99
ULANG_FORCEINLINE void * Allocate(size_t NumBytes) const
Definition Allocator.h:97
ULANG_FORCEINLINE EObserverId GenerateObserverId() const
Definition Allocator.h:101
CAllocatorInstance * _AllocatorInstance
Definition Allocator.h:103
Definition Allocator.h:258
ULANG_FORCEINLINE ForAnyElementType(const RawAllocatorType &Allocator)
Definition Allocator.h:264
ULANG_FORCEINLINE size_t GetAllocatedSize(int32_t NumAllocatedElements, size_t NumBytesPerElement) const
Definition Allocator.h:359
ULANG_FORCEINLINE void ResizeAllocation(int32_t PreviousNumElements, int32_t NumElements, size_t NumBytesPerElement)
Definition Allocator.h:313
ULANG_FORCEINLINE void MoveToEmpty(ForAnyElementType &Other)
Definition Allocator.h:272
ULANG_FORCEINLINE const RawAllocatorType & GetRawAllocator() const
Definition Allocator.h:302
ULANG_FORCEINLINE int32_t CalculateSlackGrow(int32_t NumElements, int32_t NumAllocatedElements, int32_t NumBytesPerElement) const
Definition Allocator.h:354
ULANG_FORCEINLINE bool HasAllocation()
Definition Allocator.h:364
ULANG_FORCEINLINE ForAnyElementType(AllocatorArgsType... AllocatorArgs)
Definition Allocator.h:265
ULANG_FORCEINLINE SScriptContainerElement * GetAllocation() const
Definition Allocator.h:296
ULANG_FORCEINLINE ~ForAnyElementType()
Definition Allocator.h:287
ULANG_FORCEINLINE int32_t CalculateSlackShrink(int32_t NumElements, int32_t NumAllocatedElements, int32_t NumBytesPerElement) const
Definition Allocator.h:343
ULANG_FORCEINLINE int32_t CalculateSlackReserve(int32_t NumElements, int32_t NumBytesPerElement) const
Definition Allocator.h:332
ULANG_FORCEINLINE ForAnyElementType(EDefaultInit)
Definition Allocator.h:261
Definition Allocator.h:387
ULANG_FORCEINLINE ForElementType(EDefaultInit)
Definition Allocator.h:390
ULANG_FORCEINLINE ForElementType(AllocatorArgsType &&... AllocatorArgs)
Definition Allocator.h:392
ULANG_FORCEINLINE ForElementType(const RawAllocatorType &Allocator)
Definition Allocator.h:391
ULANG_FORCEINLINE ElementType * GetAllocation() const
Definition Allocator.h:394
Definition Allocator.h:245
@ NeedsElementType
Definition Allocator.h:250
InRawAllocatorType RawAllocatorType
Definition Allocator.h:248
@ RequireRangeCheck
Definition Allocator.h:251
Definition Allocator.h:424
ULANG_FORCEINLINE bool HasAllocation() const
Definition Allocator.h:530
ULANG_FORCEINLINE int32_t CalculateSlackReserve(int32_t NumElements, int32_t NumBytesPerElement) const
Definition Allocator.h:499
uint32_t GetInitialCapacity() const
Definition Allocator.h:535
ULANG_FORCEINLINE int32_t CalculateSlackShrink(int32_t NumElements, int32_t NumAllocatedElements, int32_t NumBytesPerElement) const
Definition Allocator.h:506
ForElementType(EDefaultInit)
Definition Allocator.h:428
ULANG_FORCEINLINE const RawAllocatorType & GetRawAllocator() const
Definition Allocator.h:462
ULANG_FORCEINLINE size_t GetAllocatedSize(int32_t NumAllocatedElements, size_t NumBytesPerElement) const
Definition Allocator.h:521
ULANG_FORCEINLINE ForElementType(const RawAllocatorType &Allocator)
Definition Allocator.h:433
ULANG_FORCEINLINE void MoveToEmpty(ForElementType &Other)
Definition Allocator.h:441
ULANG_FORCEINLINE ForElementType(AllocatorArgsType... AllocatorArgs)
Definition Allocator.h:434
ULANG_FORCEINLINE int32_t CalculateSlackGrow(int32_t NumElements, int32_t NumAllocatedElements, int32_t NumBytesPerElement) const
Definition Allocator.h:513
ULANG_FORCEINLINE ElementType * GetAllocation() const
Definition Allocator.h:456
ULANG_FORCEINLINE void ResizeAllocation(int32_t PreviousNumElements, int32_t NumElements, size_t NumBytesPerElement)
Definition Allocator.h:467
Definition Allocator.h:414
@ RequireRangeCheck
Definition Allocator.h:420
void ForAnyElementType
Definition Allocator.h:557
typename SecondaryAllocator::RawAllocatorType RawAllocatorType
Definition Allocator.h:417
@ NeedsElementType
Definition Allocator.h:419
Definition VVMEngineEnvironment.h:23
EDefaultInit
Enum used to force default initialization.
Definition Common.h:378
@ DefaultInit
Definition Common.h:378
ULANG_FORCEINLINE uint32_t InterlockedCompareExchange(volatile uint32_t *Value, uint32_t ReplaceWithThis, uint32_t IfEqualToThis)
Definition WindowsThreading.h:10
EObserverId
Id type for observer pointers.
Definition Allocator.h:15
@ ObserverId_Null
Definition Allocator.h:16
SSystemParams & GetSystemParams()
Global variable for efficient access.
Definition Common.cpp:9
ULANG_FORCEINLINE int32_t DefaultCalculateSlackGrow(int32_t NumElements, int32_t NumAllocatedElements, size_t BytesPerElement, bool bAllowQuantize, uint32_t Alignment=DEFAULT_ALIGNMENT)
Definition Allocator.h:171
ULANG_FORCEINLINE int32_t DefaultCalculateSlackShrink(int32_t NumElements, int32_t NumAllocatedElements, size_t BytesPerElement, bool bAllowQuantize, uint32_t Alignment=DEFAULT_ALIGNMENT)
Definition Allocator.h:142
ULANG_FORCEINLINE T && ForwardArg(typename TRemoveReference< T >::Type &Obj)
Definition References.h:115
@ DEFAULT_ALIGNMENT
Definition Allocator.h:128
@ MIN_ALIGNMENT
Definition Allocator.h:131
ULANG_FORCEINLINE int32_t DefaultCalculateSlackReserve(int32_t NumElements, size_t BytesPerElement, bool bAllowQuantize, uint32_t Alignment=DEFAULT_ALIGNMENT)
Definition Allocator.h:207
ULANG_FORCEINLINE size_t DefaultQuantizeSize(size_t Count, uint32_t Alignment)
Definition Allocator.h:137
ULANG_FORCEINLINE uint32_t RotateCRC32(uint32_t CRC)
Definition Allocator.h:21
Definition Allocator.h:226
FRealloc _HeapRealloc
Reallocate system heap memory.
Definition Common.h:414
FFree _HeapFree
Free system heap memory.
Definition Common.h:415
FMalloc _HeapMalloc
Allocate system heap memory.
Definition Common.h:413
Definition Allocator.h:231
@ SupportsMove
Definition Allocator.h:232
@ IsZeroConstruct
Definition Allocator.h:233
Definition Allocator.h:238