28 #ifndef OVR_Allocator_h
29 #define OVR_Allocator_h
36 #if defined(OVR_CC_MSVC)
38 #pragma warning(disable : 4503)
39 #pragma warning(disable : 4786)
41 #pragma warning(disable : 4345)
52 #ifndef __PLACEMENT_NEW_INLINE
53 #define __PLACEMENT_NEW_INLINE
55 # if defined(OVR_CC_MWERKS) || defined(OVR_CC_BORLAND) || defined(OVR_CC_GNU)
63 #endif // __PLACEMENT_NEW_INLINE
73 #define OVR_MEMORY_REDEFINE_NEW_IMPL(class_name, check_delete) \
74 void* operator new(UPInt sz) \
75 { void *p = OVR_ALLOC_DEBUG(sz, __FILE__, __LINE__); return p; } \
76 void* operator new(UPInt sz, const char* file, int line) \
77 { void* p = OVR_ALLOC_DEBUG(sz, file, line); OVR_UNUSED2(file, line); return p; } \
78 void operator delete(void *p) \
79 { check_delete(class_name, p); OVR_FREE(p); } \
80 void operator delete(void *p, const char*, int) \
81 { check_delete(class_name, p); OVR_FREE(p); }
83 #define OVR_MEMORY_DEFINE_PLACEMENT_NEW \
84 void* operator new (UPInt n, void *ptr) { OVR_UNUSED(n); return ptr; } \
85 void operator delete (void *ptr, void *ptr2) { OVR_UNUSED2(ptr,ptr2); }
88 #define OVR_MEMORY_CHECK_DELETE_NONE(class_name, p)
91 #define OVR_MEMORY_REDEFINE_NEW(class_name) \
92 OVR_MEMORY_REDEFINE_NEW_IMPL(class_name, OVR_MEMORY_CHECK_DELETE_NONE)
113 return ::new(p) T(source);
117 template <
class T,
class S>
120 return ::new(p) T(source);
123 template <
class T,
class S1,
class S2>
126 return ::new(p) T(src1, src2);
133 for (
UPInt i=0; i< count; ++i, pdata +=
sizeof(T))
143 for (
UPInt i=0; i< count; ++i, pdata +=
sizeof(T))
145 Construct<T>(pdata, source);
159 for (
UPInt i=0; i<count; ++i, ++pobj)
202 virtual void Free(
void *p) = 0;
267 static AllocContainer Container;
301 virtual void Free(
void *p);
312 #define OVR_REALLOC(p,s) OVR::Allocator::GetInstance()->Realloc((p),(s))
313 #define OVR_FREE(p) OVR::Allocator::GetInstance()->Free((p))
314 #define OVR_ALLOC_ALIGNED(s,a) OVR::Allocator::GetInstance()->AllocAligned((s),(a))
315 #define OVR_FREE_ALIGNED(p) OVR::Allocator::GetInstance()->FreeAligned((p))
317 #ifdef OVR_BUILD_DEBUG
318 #define OVR_ALLOC(s) OVR::Allocator::GetInstance()->AllocDebug((s), __FILE__, __LINE__)
319 #define OVR_ALLOC_DEBUG(s,f,l) OVR::Allocator::GetInstance()->AllocDebug((s), f, l)
321 #define OVR_ALLOC(s) OVR::Allocator::GetInstance()->Alloc((s))
322 #define OVR_ALLOC_DEBUG(s,f,l) OVR::Allocator::GetInstance()->Alloc((s))
342 #if defined(OVR_DEFINE_NEW)
343 #define new OVR_DEFINE_NEW
Allocator_SingletonSupport()
OVR_FORCE_INLINE T * ConstructAlt(void *p, const S &source)
static D * InitSystemSingleton()
UPInt Data[(sizeof(D)+sizeof(UPInt)-1)/sizeof(UPInt)]
virtual void * Realloc(void *p, UPInt newSize)
OVR_FORCE_INLINE void ConstructArray(void *p, UPInt count)
OVR_FORCE_INLINE T * Construct(void *p)
static void setInstance(Allocator *palloc)
virtual void onSystemShutdown()
virtual void * Alloc(UPInt size)
virtual void * AllocDebug(UPInt size, const char *file, unsigned line)
virtual void Free(void *p)
virtual void * Realloc(void *p, UPInt newSize)=0
#define OVR_MEMORY_REDEFINE_NEW(class_name)
virtual void * AllocDebug(UPInt size, const char *file, unsigned line)
AllocContainer * pContainer
virtual void onSystemShutdown()
static Allocator * pInstance
virtual void * Alloc(UPInt size)=0
OVR_FORCE_INLINE void Destruct(T *pobj)
virtual void FreeAligned(void *p)
OVR_FORCE_INLINE void DestructArray(T *pobj, UPInt count)
virtual void Free(void *p)=0
static Allocator * GetInstance()
virtual void * AllocAligned(UPInt size, UPInt align)
#define OVR_UNUSED2(a1, a2)