Karma Engine
Loading...
Searching...
No Matches
UObjectAllocator.h
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4 UnObjAllocator.h: Unreal object allocation
5=============================================================================*/
6
7// This system needs further writing to conform with UE
8// https://github.com/ravimohan1991/KarmaEngine/discussions/10
9
10#pragma once
11
12#include "krpch.h"
13
14namespace Karma
15{
16 class UObjectBase;
17
24 typedef void (*FUObjectAllocatorCallback)(void* InObject, const std::string& InName, size_t InSize, size_t InAlignment, class UClass* InClass);
25
29 template <typename T>
31 {
32 enum { Value = false };
33 };
34
35 template <> struct TIsIntegral< bool> { enum { Value = true }; };
36 template <> struct TIsIntegral< char> { enum { Value = true }; };
37 template <> struct TIsIntegral<signed char> { enum { Value = true }; };
38 template <> struct TIsIntegral<unsigned char> { enum { Value = true }; };
39 template <> struct TIsIntegral< char16_t> { enum { Value = true }; };
40 template <> struct TIsIntegral< char32_t> { enum { Value = true }; };
41 template <> struct TIsIntegral< wchar_t> { enum { Value = true }; };
42 template <> struct TIsIntegral< short> { enum { Value = true }; };
43 template <> struct TIsIntegral<unsigned short> { enum { Value = true }; };
44 template <> struct TIsIntegral< int> { enum { Value = true }; };
45 template <> struct TIsIntegral<unsigned int> { enum { Value = true }; };
46 template <> struct TIsIntegral< long> { enum { Value = true }; };
47 template <> struct TIsIntegral<unsigned long> { enum { Value = true }; };
48 template <> struct TIsIntegral< long long> { enum { Value = true }; };
49 template <> struct TIsIntegral<unsigned long long> { enum { Value = true }; };
50
51 template <typename T> struct TIsIntegral<const T> { enum { Value = TIsIntegral<T>::Value }; };
52 template <typename T> struct TIsIntegral< volatile T> { enum { Value = TIsIntegral<T>::Value }; };
53 template <typename T> struct TIsIntegral<const volatile T> { enum { Value = TIsIntegral<T>::Value }; };
54
58 template <typename T>
60 {
61 enum { Value = false };
62 };
63
64 template <typename T> struct TIsPointer<T*> { enum { Value = true }; };
65
66 template <typename T> struct TIsPointer<const T> { enum { Value = TIsPointer<T>::Value }; };
67 template <typename T> struct TIsPointer< volatile T> { enum { Value = TIsPointer<T>::Value }; };
68 template <typename T> struct TIsPointer<const volatile T> { enum { Value = TIsPointer<T>::Value }; };
69
78 template <typename T>
79 FORCEINLINE constexpr T Align(T Val, uint64_t Alignment)
80 {
81 KR_CORE_ASSERT(TIsIntegral<T>::Value || TIsPointer<T>::Value, "Align expects an integer or pointer type");
82
83 return (T)(((uint64_t)Val + Alignment - 1) & ~(Alignment - 1));
84 }
85
95 {
96 public:
97
102 m_PermanentObjectPoolSize(0),
103 m_PermanentObjectPool(nullptr),
104 m_PermanentObjectPoolTail(nullptr),
105 m_PermanentObjectPoolExceededTail(nullptr)
106 {
107 }
108
114 void AllocatePermanentObjectPool(int32_t InPermanentObjectPoolSize);
115
124 void Initialize(uint8_t* pMemoryStart, size_t elemetSizeBytes, size_t numberOfElemets);
125
129 void BootMessage();
130
137 FORCEINLINE bool ResidesInPermanentPool(const UObjectBase* Object) const
138 {
139 return ((const uint8_t*)Object >= m_PermanentObjectPool) && ((const uint8_t*)Object < m_PermanentObjectPoolTail);
140 }
141
152 UObjectBase* AllocateUObject(size_t Size, size_t Alignment, bool bAllowPermanent);
153
157 void DumpUObjectsInformation(void* InObject, const std::string& InName, size_t InSize, size_t InAlignment, class UClass* InClass);
158
159 /*
160 * Routine for registering callback function for statistics purposes
161 *
162 * @see FUObjectAllocator::DumpUObjectsInformation
163 */
164 void RegisterUObjectsStatisticsCallback(FUObjectAllocatorCallback dumpCallback);
165
171 //void FreeUObject(UObjectBase* Object) const;
172
173 //
174 // Getters
175 //
179 uint8_t* GetPermanentObjectPoolTail() const { return m_PermanentObjectPoolTail; }
180
184 uint8_t* GetPermanentObjectPool() const { return m_PermanentObjectPool; }
185
189 uint32_t GetPermanentPoolSize() const { return m_PermanentObjectPoolSize; }
190
194 uint8_t* GetPermanentObjectPoolEnd() const { return m_PermanentObjectPoolEnd; }
195
199 uint32_t GetBareUObjectSize() const { return m_BareUObjectsSize; }
200
204 uint32_t GetAlignedUObjectSize() const { return m_AlignedUObjectsSize; }
205
209 uint32_t GetNumberOfUObjects() const { return m_NumberOfUObjects; }
210
211 private:
212
214 int32_t m_PermanentObjectPoolSize;
215
217 uint8_t* m_PermanentObjectPool;
218
220 uint8_t* m_PermanentObjectPoolTail;
221
223 uint8_t* m_PermanentObjectPoolEnd;
224
226 uint8_t* m_PermanentObjectPoolExceededTail;
227
229 uint32_t m_BareUObjectsSize;
230
232 uint32_t m_AlignedUObjectsSize;
233
240 uint32_t m_NumberOfUObjects;
241
246 };
247
249 extern KARMA_API FUObjectAllocator GUObjectAllocator;
250}
Karma's std::vector wrapper.
Definition KarmaTypes.h:128
Definition UObjectAllocator.h:95
uint8_t * GetPermanentObjectPool() const
Definition UObjectAllocator.h:184
uint32_t GetPermanentPoolSize() const
Definition UObjectAllocator.h:189
void BootMessage()
Definition UObjectAllocator.cpp:40
uint8_t * GetPermanentObjectPoolTail() const
Definition UObjectAllocator.h:179
uint8_t * GetPermanentObjectPoolEnd() const
Definition UObjectAllocator.h:194
FUObjectAllocator()
Definition UObjectAllocator.h:101
uint32_t GetNumberOfUObjects() const
Definition UObjectAllocator.h:209
uint32_t GetBareUObjectSize() const
Definition UObjectAllocator.h:199
void DumpUObjectsInformation(void *InObject, const std::string &InName, size_t InSize, size_t InAlignment, class UClass *InClass)
Definition UObjectAllocator.cpp:110
uint32_t GetAlignedUObjectSize() const
Definition UObjectAllocator.h:204
UObjectBase * AllocateUObject(size_t Size, size_t Alignment, bool bAllowPermanent)
Definition UObjectAllocator.cpp:52
void Initialize(uint8_t *pMemoryStart, size_t elemetSizeBytes, size_t numberOfElemets)
Definition UObjectAllocator.cpp:24
void AllocatePermanentObjectPool(int32_t InPermanentObjectPoolSize)
Definition UObjectAllocator.cpp:16
FORCEINLINE bool ResidesInPermanentPool(const UObjectBase *Object) const
Definition UObjectAllocator.h:137
Definition Class.h:99
Low level implementation of UObject, should not be used directly in game code Taken from UE's UObject...
Definition UObjectBase.h:34
Definition UObjectAllocator.h:31
Definition UObjectAllocator.h:60