KarmaEngine
Game Engine for practical learning and research purposes
Loading...
Searching...
No Matches
UObjectAllocator.h
Go to the documentation of this file.
1
10
11/*=============================================================================
12 UnObjAllocator.h: Unreal object allocation
13=============================================================================*/
14
15// This system needs further writing to conform with UE
16// https://github.com/ravimohan1991/KarmaEngine/discussions/10
17
18#pragma once
19
20namespace Karma
21{
22 class UObjectBase;
23
33 typedef void (*FUObjectAllocatorCallback)(void* InObject, const std::string& InName, size_t InSize, size_t InAlignment, class UClass* InClass);
34
38 template <typename T>
40 {
41 enum { Value = false };
42 };
43
44 template <> struct TIsIntegral< bool> { enum { Value = true }; };
45 template <> struct TIsIntegral< char> { enum { Value = true }; };
46 template <> struct TIsIntegral<signed char> { enum { Value = true }; };
47 template <> struct TIsIntegral<unsigned char> { enum { Value = true }; };
48 template <> struct TIsIntegral< char16_t> { enum { Value = true }; };
49 template <> struct TIsIntegral< char32_t> { enum { Value = true }; };
50 template <> struct TIsIntegral< wchar_t> { enum { Value = true }; };
51 template <> struct TIsIntegral< short> { enum { Value = true }; };
52 template <> struct TIsIntegral<unsigned short> { enum { Value = true }; };
53 template <> struct TIsIntegral< int> { enum { Value = true }; };
54 template <> struct TIsIntegral<unsigned int> { enum { Value = true }; };
55 template <> struct TIsIntegral< long> { enum { Value = true }; };
56 template <> struct TIsIntegral<unsigned long> { enum { Value = true }; };
57 template <> struct TIsIntegral< long long> { enum { Value = true }; };
58 template <> struct TIsIntegral<unsigned long long> { enum { Value = true }; };
59
60 template <typename T> struct TIsIntegral<const T> { enum { Value = TIsIntegral<T>::Value }; };
61 template <typename T> struct TIsIntegral< volatile T> { enum { Value = TIsIntegral<T>::Value }; };
62
63 template <typename T> struct TIsIntegral<const volatile T> { enum { Value = TIsIntegral<T>::Value }; };
64
71 template <typename T>
73 {
74 enum { Value = false };
75 };
76
77 template <typename T> struct TIsPointer<T*> { enum { Value = true }; };
78
79 template <typename T> struct TIsPointer<const T> { enum { Value = TIsPointer<T>::Value }; };
80 template <typename T> struct TIsPointer< volatile T> { enum { Value = TIsPointer<T>::Value }; };
81
82 template <typename T> struct TIsPointer<const volatile T> { enum { Value = TIsPointer<T>::Value }; };
83
92 template <typename T>
93 FORCEINLINE constexpr T Align(T Val, uint64_t Alignment)
94 {
95 KR_CORE_ASSERT(TIsIntegral<T>::Value || TIsPointer<T>::Value, "Align expects an integer or pointer type");
96
97 return (T)(((uint64_t)Val + Alignment - 1) & ~(Alignment - 1));
98 }
99
110 {
111 public:
112
119 m_PermanentObjectPoolSize(0),
120 m_PermanentObjectPool(nullptr),
121 m_PermanentObjectPoolTail(nullptr),
122 m_PermanentObjectPoolExceededTail(nullptr)
123 {
124 }
125
134 void AllocatePermanentObjectPool(int32_t InPermanentObjectPoolSize);
135
145 void Initialize(uint8_t* pMemoryStart, size_t elemetSizeBytes, size_t numberOfElemets);
146
152 void BootMessage();
153
163 {
164 return ((const uint8_t*)Object >= m_PermanentObjectPool) && ((const uint8_t*)Object < m_PermanentObjectPoolTail);
165 }
166
180 UObjectBase* AllocateUObject(size_t Size, size_t Alignment, bool bAllowPermanent);
181
187 void DumpUObjectsInformation(void* InObject, const std::string& InName, size_t InSize, size_t InAlignment, class UClass* InClass);
188
199
205 //void FreeUObject(UObjectBase* Object) const;
206
207 //
208 // Getters
209 //
215 uint8_t* GetPermanentObjectPoolTail() const { return m_PermanentObjectPoolTail; }
216
222 uint8_t* GetPermanentObjectPool() const { return m_PermanentObjectPool; }
223
229 uint32_t GetPermanentPoolSize() const { return m_PermanentObjectPoolSize; }
230
236 uint8_t* GetPermanentObjectPoolEnd() const { return m_PermanentObjectPoolEnd; }
237
243 uint32_t GetBareUObjectSize() const { return m_BareUObjectsSize; }
244
250 uint32_t GetAlignedUObjectSize() const { return m_AlignedUObjectsSize; }
251
257 uint32_t GetNumberOfUObjects() const { return m_NumberOfUObjects; }
258
259 private:
260
262 int32_t m_PermanentObjectPoolSize;
263
265 uint8_t* m_PermanentObjectPool;
266
268 uint8_t* m_PermanentObjectPoolTail;
269
271 uint8_t* m_PermanentObjectPoolEnd;
272
274 uint8_t* m_PermanentObjectPoolExceededTail;
275
277 uint32_t m_BareUObjectsSize;
278
280 uint32_t m_AlignedUObjectsSize;
281
288 uint32_t m_NumberOfUObjects;
289
294 };
295
303 extern KARMA_API FUObjectAllocator GUObjectAllocator;
304}
#define KARMA_API
Defining Karma's API macro for storage class information.
Definition Core.h:41
#define FORCEINLINE
Typical inlining macro for clarity.
Definition Core.h:157
void(* FUObjectAllocatorCallback)(void *InObject, const std::string &InName, size_t InSize, size_t InAlignment, class UClass *InClass)
A definition useful for UObjects statistics.
Definition UObjectAllocator.h:33
FORCEINLINE constexpr T Align(T Val, uint64_t Alignment)
Definition UObjectAllocator.h:93
uint8_t * GetPermanentObjectPool() const
Definition UObjectAllocator.h:222
uint32_t GetPermanentPoolSize() const
Definition UObjectAllocator.h:229
void BootMessage()
Definition UObjectAllocator.cpp:32
uint8_t * GetPermanentObjectPoolTail() const
Definition UObjectAllocator.h:215
uint8_t * GetPermanentObjectPoolEnd() const
Definition UObjectAllocator.h:236
FUObjectAllocator()
Definition UObjectAllocator.h:118
void RegisterUObjectsStatisticsCallback(FUObjectAllocatorCallback dumpCallback)
Definition UObjectAllocator.cpp:97
uint32_t GetNumberOfUObjects() const
Definition UObjectAllocator.h:257
uint32_t GetBareUObjectSize() const
Definition UObjectAllocator.h:243
void DumpUObjectsInformation(void *InObject, const std::string &InName, size_t InSize, size_t InAlignment, class UClass *InClass)
Definition UObjectAllocator.cpp:102
uint32_t GetAlignedUObjectSize() const
Definition UObjectAllocator.h:250
UObjectBase * AllocateUObject(size_t Size, size_t Alignment, bool bAllowPermanent)
Allocates a UObjectBase from the free store or the permanent object pool.
Definition UObjectAllocator.cpp:44
void Initialize(uint8_t *pMemoryStart, size_t elemetSizeBytes, size_t numberOfElemets)
Definition UObjectAllocator.cpp:19
void AllocatePermanentObjectPool(int32_t InPermanentObjectPoolSize)
Definition UObjectAllocator.cpp:11
FORCEINLINE bool ResidesInPermanentPool(const UObjectBase *Object) const
Definition UObjectAllocator.h:162
An object class.
Definition Class.h:158
Low level implementation of UObject, should not be used directly in game code.
Definition UObjectBase.h:36
Karma's std::vector wrapper.
Definition KarmaTypes.h:152
Definition UObjectAllocator.h:40
Traits class which tests if a type is a pointer.
Definition UObjectAllocator.h:73