UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
AnsiAllocator.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=====================================================================================================
4 AnsiAllocator.h: helper allocator that allocates directly from standard library allocation functions
5=======================================================================================================*/
6
7#pragma once
8
9#include "CoreTypes.h"
12
13namespace UE::Core::Private
14{
15 [[noreturn]] CORE_API void OnInvalidAnsiAllocatorNum(int32 NewNum, SIZE_T NumBytesPerElement);
16}
17
20{
21public:
22 using SizeType = int32;
23
24 enum { NeedsElementType = false };
25 enum { RequireRangeCheck = true };
26
29
31 {
32 public:
35 : Data(nullptr)
36 {}
37
44 {
45 check(this != &Other);
46
47 if (Data)
48 {
49 ::free(Data);
50 }
51
52 Data = Other.Data;
53 Other.Data = nullptr;
54 }
55
58 {
59 if (Data)
60 {
61 ::free(Data);
62 }
63 }
64
65 // FContainerAllocatorInterface
67 {
68 return Data;
69 }
70 CORE_API void ResizeAllocation(SizeType CurrentNum, SizeType NewMax, SIZE_T NumBytesPerElement);
72 {
73 return DefaultCalculateSlackReserve(NewMax, NumBytesPerElement, false);
74 }
75 SizeType CalculateSlackShrink(SizeType NewMax, SizeType CurrentMax, SIZE_T NumBytesPerElement) const
76 {
77 return DefaultCalculateSlackShrink(NewMax, CurrentMax, NumBytesPerElement, false);
78 }
79 SizeType CalculateSlackGrow(SizeType NewMax, SizeType CurrentMax, SIZE_T NumBytesPerElement) const
80 {
81 return DefaultCalculateSlackGrow(NewMax, CurrentMax, NumBytesPerElement, false);
82 }
83
84 SIZE_T GetAllocatedSize(SizeType CurrentMax, SIZE_T NumBytesPerElement) const
85 {
86 return CurrentMax * NumBytesPerElement;
87 }
88
89 bool HasAllocation() const
90 {
91 return !!Data;
92 }
93
95 {
96 return 0;
97 }
98
99 private:
101 ForAnyElementType& operator=(const ForAnyElementType&);
102
105 };
106
107 template<typename ElementType>
109 {
110 public:
111
115
116 FORCEINLINE ElementType* GetAllocation() const
117 {
118 return (ElementType*)ForAnyElementType::GetAllocation();
119 }
120 };
121};
122
123template <>
125{
126 enum { IsZeroConstruct = true };
127};
128
130class FAnsiSetAllocator : public TSetAllocator<FAnsiAllocator, TInlineAllocator<1, FAnsiAllocator>>
131{
132};
#define FORCEINLINE
Definition AndroidPlatform.h:140
#define check(expr)
Definition AssertionMacros.h:314
UE_FORCEINLINE_HINT SizeType DefaultCalculateSlackReserve(SizeType NewMax, SIZE_T BytesPerElement, bool bAllowQuantize, uint32 Alignment=DEFAULT_ALIGNMENT)
Definition ContainerAllocationPolicies.h:223
UE_FORCEINLINE_HINT SizeType DefaultCalculateSlackShrink(SizeType NewMax, SizeType CurrentMax, SIZE_T BytesPerElement, bool bAllowQuantize, uint32 Alignment=DEFAULT_ALIGNMENT)
Definition ContainerAllocationPolicies.h:139
UE_FORCEINLINE_HINT SizeType DefaultCalculateSlackGrow(SizeType NewMax, SizeType CurrentMax, SIZE_T BytesPerElement, bool bAllowQuantize, uint32 Alignment=DEFAULT_ALIGNMENT)
Definition ContainerAllocationPolicies.h:169
FPlatformTypes::SIZE_T SIZE_T
An unsigned integer the same size as a pointer, the same as UPTRINT.
Definition Platform.h:1150
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
free(DecoderMem)
Definition AnsiAllocator.h:31
bool HasAllocation() const
Definition AnsiAllocator.h:89
SizeType CalculateSlackShrink(SizeType NewMax, SizeType CurrentMax, SIZE_T NumBytesPerElement) const
Definition AnsiAllocator.h:75
SIZE_T GetAllocatedSize(SizeType CurrentMax, SIZE_T NumBytesPerElement) const
Definition AnsiAllocator.h:84
SizeType CalculateSlackGrow(SizeType NewMax, SizeType CurrentMax, SIZE_T NumBytesPerElement) const
Definition AnsiAllocator.h:79
SizeType GetInitialCapacity() const
Definition AnsiAllocator.h:94
FORCEINLINE void MoveToEmpty(ForAnyElementType &Other)
Definition AnsiAllocator.h:43
ForAnyElementType()
Definition AnsiAllocator.h:34
CORE_API void ResizeAllocation(SizeType CurrentNum, SizeType NewMax, SIZE_T NumBytesPerElement)
Definition AnsiAllocator.cpp:12
FORCEINLINE ~ForAnyElementType()
Definition AnsiAllocator.h:57
SizeType CalculateSlackReserve(SizeType NewMax, SIZE_T NumBytesPerElement) const
Definition AnsiAllocator.h:71
FORCEINLINE FScriptContainerElement * GetAllocation() const
Definition AnsiAllocator.h:66
Definition AnsiAllocator.h:109
FORCEINLINE ElementType * GetAllocation() const
Definition AnsiAllocator.h:116
ForElementType()
Definition AnsiAllocator.h:113
Definition AnsiAllocator.h:20
int32 SizeType
Definition AnsiAllocator.h:22
@ RequireRangeCheck
Definition AnsiAllocator.h:25
FAnsiAllocator ElementAllocator
Definition AnsiAllocator.h:27
FAnsiAllocator BitArrayAllocator
Definition AnsiAllocator.h:28
@ NeedsElementType
Definition AnsiAllocator.h:24
Definition AnsiAllocator.h:131
Definition ContainerAllocationPolicies.h:1662
implementation
Definition PlayInEditorLoadingScope.h:8
CORE_API void OnInvalidAnsiAllocatorNum(int32 NewNum, SIZE_T NumBytesPerElement)
Definition AnsiAllocator.cpp:6
Definition ContainerAllocationPolicies.h:242
Definition ContainerAllocationPolicies.h:247
@ IsZeroConstruct
Definition ContainerAllocationPolicies.h:248
Definition ContainerAllocationPolicies.h:256