aboutsummaryrefslogtreecommitdiffstats
path: root/LibOVR/Src/Kernel/OVR_Allocator.h
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2015-03-21 23:01:12 +0100
committerSven Gothel <[email protected]>2015-03-21 23:01:12 +0100
commit0c5c4be020c2d55540058a49b2a879f46d5a1e13 (patch)
tree00f84c2ca18cc233b826014094b9cad0769a3ea5 /LibOVR/Src/Kernel/OVR_Allocator.h
parentcbbd775b6c754927632c333ff01424a0d2048c7c (diff)
parente490c3c7f7bb5461cfa78a214827aa534fb43a3e (diff)
Merge branch 'vanilla_0.4.4' and resolve conflicts
TODO: Validate for removed patches due to relocation Resolved Conflicts: LibOVR/Src/Kernel/OVR_ThreadsWinAPI.cpp LibOVR/Src/OVR_Linux_HMDDevice.cpp LibOVR/Src/OVR_OSX_HMDDevice.cpp LibOVR/Src/OVR_Profile.cpp LibOVR/Src/OVR_Sensor2Impl.cpp LibOVR/Src/OVR_SensorFusion.cpp LibOVR/Src/OVR_SensorImpl.cpp LibOVR/Src/OVR_Win32_DeviceStatus.cpp LibOVR/Src/OVR_Win32_HIDDevice.cpp LibOVR/Src/OVR_Win32_HIDDevice.h LibOVR/Src/OVR_Win32_HMDDevice.cpp
Diffstat (limited to 'LibOVR/Src/Kernel/OVR_Allocator.h')
-rw-r--r--LibOVR/Src/Kernel/OVR_Allocator.h61
1 files changed, 37 insertions, 24 deletions
diff --git a/LibOVR/Src/Kernel/OVR_Allocator.h b/LibOVR/Src/Kernel/OVR_Allocator.h
index b862557..dcf097d 100644
--- a/LibOVR/Src/Kernel/OVR_Allocator.h
+++ b/LibOVR/Src/Kernel/OVR_Allocator.h
@@ -1,21 +1,21 @@
/************************************************************************************
-PublicHeader: OVR.h
+PublicHeader: OVR_Kernel.h
Filename : OVR_Allocator.h
Content : Installable memory allocator
Created : September 19, 2012
Notes :
-Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved.
+Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
-Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License");
+Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
you may not use the Oculus VR Rift SDK except in compliance with the License,
which is provided at the time of installation or download, or which
otherwise accompanies this software in either electronic or hard copy form.
You may obtain a copy of the License at
-http://www.oculusvr.com/licenses/LICENSE-3.1
+http://www.oculusvr.com/licenses/LICENSE-3.2
Unless required by applicable law or agreed to in writing, the Oculus VR SDK
distributed under the License is distributed on an "AS IS" BASIS,
@@ -56,7 +56,7 @@ limitations under the License.
# include <new>
# else
// Useful on MSVC
- OVR_FORCE_INLINE void* operator new (OVR::UPInt n, void *ptr) { OVR_UNUSED(n); return ptr; }
+ OVR_FORCE_INLINE void* operator new (size_t n, void *ptr) { OVR_UNUSED(n); return ptr; }
OVR_FORCE_INLINE void operator delete (void *, void *) { }
# endif
@@ -71,9 +71,9 @@ limitations under the License.
// class member operator new.
#define OVR_MEMORY_REDEFINE_NEW_IMPL(class_name, check_delete) \
- void* operator new(UPInt sz) \
+ void* operator new(size_t sz) \
{ void *p = OVR_ALLOC_DEBUG(sz, __FILE__, __LINE__); return p; } \
- void* operator new(UPInt sz, const char* file, int line) \
+ void* operator new(size_t sz, const char* file, int line) \
{ void* p = OVR_ALLOC_DEBUG(sz, file, line); OVR_UNUSED2(file, line); return p; } \
void operator delete(void *p) \
{ check_delete(class_name, p); OVR_FREE(p); } \
@@ -81,7 +81,7 @@ limitations under the License.
{ check_delete(class_name, p); OVR_FREE(p); }
#define OVR_MEMORY_DEFINE_PLACEMENT_NEW \
- void* operator new (UPInt n, void *ptr) { OVR_UNUSED(n); return ptr; } \
+ void* operator new (size_t n, void *ptr) { OVR_UNUSED(n); return ptr; } \
void operator delete (void *ptr, void *ptr2) { OVR_UNUSED2(ptr,ptr2); }
@@ -127,20 +127,20 @@ OVR_FORCE_INLINE T* ConstructAlt(void *p, const S1& src1, const S2& src2)
}
template <class T>
-OVR_FORCE_INLINE void ConstructArray(void *p, UPInt count)
+OVR_FORCE_INLINE void ConstructArray(void *p, size_t count)
{
- UByte *pdata = (UByte*)p;
- for (UPInt i=0; i< count; ++i, pdata += sizeof(T))
+ uint8_t *pdata = (uint8_t*)p;
+ for (size_t i=0; i< count; ++i, pdata += sizeof(T))
{
Construct<T>(pdata);
}
}
template <class T>
-OVR_FORCE_INLINE void ConstructArray(void *p, UPInt count, const T& source)
+OVR_FORCE_INLINE void ConstructArray(void *p, size_t count, const T& source)
{
- UByte *pdata = (UByte*)p;
- for (UPInt i=0; i< count; ++i, pdata += sizeof(T))
+ uint8_t *pdata = (uint8_t*)p;
+ for (size_t i=0; i< count; ++i, pdata += sizeof(T))
{
Construct<T>(pdata, source);
}
@@ -154,9 +154,9 @@ OVR_FORCE_INLINE void Destruct(T *pobj)
}
template <class T>
-OVR_FORCE_INLINE void DestructArray(T *pobj, UPInt count)
+OVR_FORCE_INLINE void DestructArray(T *pobj, size_t count)
{
- for (UPInt i=0; i<count; ++i, ++pobj)
+ for (size_t i=0; i<count; ++i, ++pobj)
pobj->~T();
}
@@ -178,15 +178,16 @@ class Allocator
{
friend class System;
public:
+ virtual ~Allocator(){}
// *** Standard Alignment Alloc/Free
// Allocate memory of specified size with default alignment.
// Alloc of size==0 will allocate a tiny block & return a valid pointer;
// this makes it suitable for new operator.
- virtual void* Alloc(UPInt size) = 0;
+ virtual void* Alloc(size_t size) = 0;
// Same as Alloc, but provides an option of passing debug data.
- virtual void* AllocDebug(UPInt size, const char* file, unsigned line)
+ virtual void* AllocDebug(size_t size, const char* file, unsigned line)
{ OVR_UNUSED2(file, line); return Alloc(size); }
// Reallocate memory block to a new size, copying data if necessary. Returns the pointer to
@@ -195,7 +196,7 @@ public:
// Realloc to decrease size will never fail.
// Realloc of pointer == 0 is equivalent to Alloc
// Realloc to size == 0, shrinks to the minimal size, pointer remains valid and requires Free().
- virtual void* Realloc(void* p, UPInt newSize) = 0;
+ virtual void* Realloc(void* p, size_t newSize) = 0;
// Frees memory allocated by Alloc/Realloc.
// Free of null pointer is valid and will do nothing.
@@ -207,7 +208,7 @@ public:
// Allocate memory of specified alignment.
// Memory allocated with AllocAligned MUST be freed with FreeAligned.
// Default implementation will delegate to Alloc/Free after doing rounding.
- virtual void* AllocAligned(UPInt size, UPInt align);
+ virtual void* AllocAligned(size_t size, size_t align);
// Frees memory allocated with AllocAligned.
virtual void FreeAligned(void* p);
@@ -250,7 +251,7 @@ class Allocator_SingletonSupport : public Allocator
{
struct AllocContainer
{
- UPInt Data[(sizeof(D) + sizeof(UPInt)-1) / sizeof(UPInt)];
+ size_t Data[(sizeof(D) + sizeof(size_t)-1) / sizeof(size_t)];
bool Initialized;
AllocContainer() : Initialized(0) { }
};
@@ -295,9 +296,9 @@ protected:
class DefaultAllocator : public Allocator_SingletonSupport<DefaultAllocator>
{
public:
- virtual void* Alloc(UPInt size);
- virtual void* AllocDebug(UPInt size, const char* file, unsigned line);
- virtual void* Realloc(void* p, UPInt newSize);
+ virtual void* Alloc(size_t size);
+ virtual void* AllocDebug(size_t size, const char* file, unsigned line);
+ virtual void* Realloc(void* p, size_t newSize);
virtual void Free(void *p);
};
@@ -335,6 +336,18 @@ public:
};
+//------------------------------------------------------------------------
+// ***** Mapped memory allocation
+//
+// Equates to VirtualAlloc/VirtualFree on Windows, mmap/munmap on Unix.
+// These are useful for when you need system-supplied memory pages.
+// These are also useful for when you need to allocate memory in a way
+// that doesn't affect the application heap.
+
+void* MMapAlloc(size_t size);
+void MMapFree(void* memory, size_t size);
+
+
} // OVR