17 #ifndef INC_KY_Kernel_Allocator_H
18 #define INC_KY_Kernel_Allocator_H
40 KY_INLINE T* Construct(
void *p)
46 KY_INLINE T* Construct(
void *p, const T& source)
48 return ::new(p) T(source);
52 template <class T, class S>
53 KY_INLINE T* ConstructAlt(
void *p, const S& source)
55 return ::new(p) T(source);
58 template <class T, class S1, class S2>
59 KY_INLINE T* ConstructAlt(
void *p, const S1& src1, const S2& src2)
61 return ::new(p) T(src1, src2);
65 KY_INLINE
void ConstructArray(
void *p, UPInt count)
68 for (UPInt i=0; i< count; ++i, pdata +=
sizeof(T))
75 KY_INLINE
void ConstructArray(
void *p, UPInt count,
const T& source)
78 for (UPInt i=0; i< count; ++i, pdata +=
sizeof(T))
80 Construct<T>(pdata, source);
85 KY_INLINE
void Destruct(T *pobj)
91 KY_INLINE
void DestructArray(T *pobj, UPInt count)
93 for (UPInt i=0; i<count; ++i, ++pobj)
107 template<
int SID = Stat_Default_Mem>
108 class AllocatorBaseLH
111 enum { StatId = SID };
113 #ifdef KY_CONFIG_DEBUG
114 static void* Alloc(
const void* pheapAddr, UPInt size,
const char* pfile,
unsigned line)
116 return Memory::AllocAutoHeap(pheapAddr, size, AllocInfo(StatId, pfile, line));
118 static void* Realloc(
const void*,
void* p, UPInt newSize,
const char* pfile,
unsigned line)
120 KY_UNUSED2(pfile, line);
121 return Memory::ReallocAutoHeap(p, newSize);
126 static void* Alloc(
const void* pheapAddr, UPInt size,
const char*,
unsigned)
128 return Memory::AllocAutoHeap(pheapAddr, size, AllocInfo(StatId, 0, 0));
130 static void* Realloc(
const void*,
void* p, UPInt newSize,
const char*,
unsigned)
132 return Memory::ReallocAutoHeap(p, newSize);
137 static void Free(
void *p)
153 template<
int SID = Stat_Default_Mem>
154 class AllocatorBaseDH
157 enum { StatId = SID };
159 #ifdef KY_CONFIG_DEBUG
160 static void* Alloc(
const void* pheap, UPInt size,
const char* pfile,
unsigned line)
162 return Memory::AllocInHeap((MemoryHeap*)pheap, size, AllocInfo(StatId, pfile, line));
164 static void* Realloc(
const void* pheap,
void* p, UPInt newSize,
const char* pfile,
unsigned line)
166 KY_UNUSED2(pfile, line);
167 return Memory::ReallocInHeap((MemoryHeap*)pheap, p, newSize);
172 static void* Alloc(
const void* pheap, UPInt size,
const char*,
unsigned)
174 return Memory::AllocInHeap((MemoryHeap*)pheap, size, AllocInfo(StatId, 0, 0));
176 static void* Realloc(
const void* pheap,
void* p, UPInt newSize,
const char*,
unsigned)
178 return Memory::ReallocInHeap((MemoryHeap*)pheap, p, newSize);
183 static void Free(
void *p)
195 template<
int SID = Stat_Default_Mem>
196 class AllocatorBaseGH
199 enum { StatId = SID };
201 #ifdef KY_CONFIG_DEBUG
202 static void* Alloc(
const void*, UPInt size,
const char* pfile,
unsigned line)
204 return Memory::Alloc(size, AllocInfo(StatId, pfile, line));
206 static void* Realloc(
const void*,
void *p, UPInt newSize,
const char* pfile,
unsigned line)
208 KY_UNUSED2(pfile, line);
209 return Memory::Realloc(p, newSize);
214 static void* Alloc(
const void*, UPInt size,
const char*,
unsigned)
216 return Memory::Alloc(size, AllocInfo(StatId, 0, 0));
218 static void* Realloc(
const void*,
void *p, UPInt newSize,
const char*,
unsigned)
220 return Memory::Realloc(p, newSize);
225 static void Free(
void *p)
241 static void Construct(
void *) {}
242 static void Construct(
void *p,
const T& source)
249 static void ConstructAlt(
void *p,
const S& source)
254 static void ConstructArray(
void*, UPInt) {}
256 static void ConstructArray(
void* p, UPInt count,
const T& source)
259 for (UPInt i=0; i< count; ++i, pdata +=
sizeof(T))
263 static void ConstructArray(
void* p, UPInt count,
const T* psource)
265 memcpy(p, psource,
sizeof(T) * count);
268 static void Destruct(T*) {}
269 static void DestructArray(T*, UPInt) {}
271 static void CopyArrayForward(T* dst,
const T* src, UPInt count)
273 memmove(dst, src, count *
sizeof(T));
276 static void CopyArrayBackward(T* dst,
const T* src, UPInt count)
278 memmove(dst, src, count *
sizeof(T));
281 static bool IsMovable() {
return true; }
293 static void Construct(
void* p)
298 static
void Construct(
void* p, const T& source)
305 static
void ConstructAlt(
void* p, const S& source)
310 static
void ConstructArray(
void* p, UPInt count)
313 for (UPInt i=0; i< count; ++i, pdata +=
sizeof(T))
317 static void ConstructArray(
void* p, UPInt count,
const T& source)
320 for (UPInt i=0; i< count; ++i, pdata +=
sizeof(T))
321 Construct(pdata, source);
324 static void ConstructArray(
void* p, UPInt count,
const T* psource)
327 for (UPInt i=0; i< count; ++i, pdata +=
sizeof(T))
328 Construct(pdata, *psource++);
331 static void Destruct(T* p)
337 static void DestructArray(T* p, UPInt count)
340 for (UPInt i=0; i<count; ++i, --p)
344 static void CopyArrayForward(T* dst,
const T* src, UPInt count)
346 memmove(dst, src, count *
sizeof(T));
349 static void CopyArrayBackward(T* dst,
const T* src, UPInt count)
351 memmove(dst, src, count *
sizeof(T));
354 static bool IsMovable() {
return true; }
366 static void Construct(
void* p)
371 static
void Construct(
void* p, const T& source)
378 static
void ConstructAlt(
void* p, const S& source)
383 static
void ConstructArray(
void* p, UPInt count)
386 for (UPInt i=0; i< count; ++i, pdata +=
sizeof(T))
390 static void ConstructArray(
void* p, UPInt count,
const T& source)
393 for (UPInt i=0; i< count; ++i, pdata +=
sizeof(T))
394 Construct(pdata, source);
397 static void ConstructArray(
void* p, UPInt count,
const T* psource)
400 for (UPInt i=0; i< count; ++i, pdata +=
sizeof(T))
401 Construct(pdata, *psource++);
404 static void Destruct(T* p)
410 static void DestructArray(T* p, UPInt count)
413 for (UPInt i=0; i<count; ++i, --p)
417 static void CopyArrayForward(T* dst,
const T* src, UPInt count)
419 for(UPInt i = 0; i < count; ++i)
423 static void CopyArrayBackward(T* dst,
const T* src, UPInt count)
425 for(UPInt i = count; i; --i)
429 static bool IsMovable() {
return false; }
438 template<
class T,
int SID = Stat_Default_Mem>
struct AllocatorGH_POD : AllocatorBaseGH<SID>, ConstructorPOD<T> {};
439 template<
class T,
int SID = Stat_Default_Mem>
struct AllocatorGH : AllocatorBaseGH<SID>, ConstructorMov<T> {};
440 template<
class T,
int SID = Stat_Default_Mem>
struct AllocatorGH_CPP : AllocatorBaseGH<SID>, ConstructorCPP<T> {};
442 template<
class T,
int SID = Stat_Default_Mem>
struct AllocatorLH_POD : AllocatorBaseLH<SID>, ConstructorPOD<T> {};
443 template<
class T,
int SID = Stat_Default_Mem>
struct AllocatorLH : AllocatorBaseLH<SID>, ConstructorMov<T> {};
444 template<
class T,
int SID = Stat_Default_Mem>
struct AllocatorLH_CPP : AllocatorBaseLH<SID>, ConstructorCPP<T> {};
446 template<
class T,
int SID = Stat_Default_Mem>
struct AllocatorDH_POD : AllocatorBaseDH<SID>, ConstructorPOD<T> {};
447 template<
class T,
int SID = Stat_Default_Mem>
struct AllocatorDH : AllocatorBaseDH<SID>, ConstructorMov<T> {};
448 template<
class T,
int SID = Stat_Default_Mem>
struct AllocatorDH_CPP : AllocatorBaseDH<SID>, ConstructorCPP<T> {};
453 #if defined(KY_DEFINE_NEW)
454 #define new KY_DEFINE_NEW
std::uint8_t UByte
uint8_t
Definition: SF_Types.h:134
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17