summaryrefslogtreecommitdiffstats
path: root/Common/interface
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-09-09 03:47:11 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-09-09 03:47:11 +0000
commitff51bc498f3411348227d326f784d3082616beb2 (patch)
tree08da10acdbe47ece979885bb653a23d4045215b6 /Common/interface
parentAdded alignment parameter to allocation managers (fixed https://github.com/Di... (diff)
downloadDiligentCore-ff51bc498f3411348227d326f784d3082616beb2.tar.gz
DiligentCore-ff51bc498f3411348227d326f784d3082616beb2.zip
Fixed https://github.com/DiligentGraphics/DiligentCore/issues/31 (Remove debug info from STDAllocator in release build)
Diffstat (limited to 'Common/interface')
-rw-r--r--Common/interface/RefCountedObjectImpl.h42
-rw-r--r--Common/interface/STDAllocator.h55
2 files changed, 62 insertions, 35 deletions
diff --git a/Common/interface/RefCountedObjectImpl.h b/Common/interface/RefCountedObjectImpl.h
index 4f8176dc..edabc22e 100644
--- a/Common/interface/RefCountedObjectImpl.h
+++ b/Common/interface/RefCountedObjectImpl.h
@@ -593,21 +593,25 @@ template<typename ObjectType, typename AllocatorType = IMemoryAllocator>
class MakeNewRCObj
{
public:
- MakeNewRCObj(AllocatorType &Allocator, const Char* dbgDescription, const char* dbgFileName, const Int32 dbgLineNumber, IObject* pOwner = nullptr)noexcept :
+ MakeNewRCObj(AllocatorType &Allocator, const Char* Description, const char* FileName, const Int32 LineNumber, IObject* pOwner = nullptr)noexcept :
m_pAllocator(&Allocator),
- m_pOwner(pOwner),
- m_dbgDescription(dbgDescription),
- m_dbgFileName(dbgFileName),
- m_dbgLineNumber(dbgLineNumber)
+ m_pOwner(pOwner)
+#ifdef DEVELOPMENT
+ , m_dvpDescription(Description)
+ , m_dvpFileName (FileName)
+ , m_dvpLineNumber (LineNumber)
+#endif
{
}
MakeNewRCObj(IObject* pOwner = nullptr)noexcept :
- m_pAllocator(nullptr),
- m_pOwner(pOwner),
- m_dbgDescription(nullptr),
- m_dbgFileName(nullptr),
- m_dbgLineNumber(0)
+ m_pAllocator (nullptr),
+ m_pOwner (pOwner)
+#ifdef DEVELOPMENT
+ , m_dvpDescription(nullptr)
+ , m_dvpFileName (nullptr)
+ , m_dvpLineNumber (0)
+#endif
{}
MakeNewRCObj(const MakeNewRCObj&) = delete;
@@ -632,10 +636,15 @@ public:
ObjectType *pObj = nullptr;
try
{
+#ifndef DEVELOPMENT
+ static constexpr char* m_dvpDescription = "<Unavailable in release build>";
+ static constexpr char* m_dvpFileName = "<Unavailable in release build>";
+ static constexpr Int32 m_dvpLineNumber = -1;
+#endif
// Operators new and delete of RefCountedObject are private and only accessible
// by methods of MakeNewRCObj
if(m_pAllocator)
- pObj = new(*m_pAllocator, m_dbgDescription, m_dbgFileName, m_dbgLineNumber) ObjectType(pRefCounters, std::forward<CtorArgTypes>(CtorArgs)... );
+ pObj = new(*m_pAllocator, m_dvpDescription, m_dvpFileName, m_dvpLineNumber) ObjectType(pRefCounters, std::forward<CtorArgTypes>(CtorArgs)... );
else
pObj = new ObjectType( pRefCounters, std::forward<CtorArgTypes>(CtorArgs)... );
if(pNewRefCounters != nullptr)
@@ -652,10 +661,13 @@ public:
private:
AllocatorType* const m_pAllocator;
- IObject* const m_pOwner;
- const Char* const m_dbgDescription;
- const char* const m_dbgFileName;
- const Int32 m_dbgLineNumber;
+ IObject* const m_pOwner;
+
+#ifdef DEVELOPMENT
+ const Char* const m_dvpDescription;
+ const char* const m_dvpFileName;
+ Int32 const m_dvpLineNumber;
+#endif
};
#define NEW_RC_OBJ(Allocator, Desc, Type, ...) MakeNewRCObj<Type, typename std::remove_reference<decltype(Allocator)>::type>(Allocator, Desc, __FILE__, __LINE__, ##__VA_ARGS__)
diff --git a/Common/interface/STDAllocator.h b/Common/interface/STDAllocator.h
index ecc18e1e..a58545eb 100644
--- a/Common/interface/STDAllocator.h
+++ b/Common/interface/STDAllocator.h
@@ -45,29 +45,35 @@ struct STDAllocator
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
- STDAllocator(AllocatorType& Allocator, const Char* dbgDescription, const Char* dbgFileName, const Int32 dbgLineNumber)noexcept :
- m_Allocator(Allocator),
- m_dbgDescription(dbgDescription),
- m_dbgFileName(dbgFileName),
- m_dbgLineNumber(dbgLineNumber)
+ STDAllocator(AllocatorType& Allocator, const Char* Description, const Char* FileName, const Int32 LineNumber)noexcept :
+ m_Allocator (Allocator)
+#ifdef DEVELOPMENT
+ , m_dvpDescription(Description)
+ , m_dvpFileName (FileName)
+ , m_dvpLineNumber (LineNumber)
+#endif
{
}
template <class U>
STDAllocator(const STDAllocator<U, AllocatorType>& other)noexcept :
- m_Allocator(other.m_Allocator),
- m_dbgDescription(other.m_dbgDescription),
- m_dbgFileName(other.m_dbgFileName),
- m_dbgLineNumber(other.m_dbgLineNumber)
+ m_Allocator (other.m_Allocator)
+#ifdef DEVELOPMENT
+ , m_dvpDescription(other.m_dvpDescription)
+ , m_dvpFileName (other.m_dvpFileName)
+ , m_dvpLineNumber (other.m_dvpLineNumber)
+#endif
{
}
template <class U>
STDAllocator(STDAllocator<U, AllocatorType>&& other)noexcept :
- m_Allocator(other.m_Allocator),
- m_dbgDescription(other.m_dbgDescription),
- m_dbgFileName(other.m_dbgFileName),
- m_dbgLineNumber(other.m_dbgLineNumber)
+ m_Allocator (other.m_Allocator)
+#ifdef DEVELOPMENT
+ , m_dvpDescription(other.m_dvpDescription)
+ , m_dvpFileName (other.m_dvpFileName)
+ , m_dvpLineNumber (other.m_dvpLineNumber)
+#endif
{
}
@@ -76,9 +82,11 @@ struct STDAllocator
{
// Android build requires this operator to be defined - I have no idea why
VERIFY_EXPR(&m_Allocator == &other.m_Allocator);
- m_dbgDescription = other.m_dbgDescription;
- m_dbgFileName = other.m_dbgFileName;
- m_dbgLineNumber = other.m_dbgLineNumber;
+#ifdef DEVELOPMENT
+ m_dvpDescription = other.m_dvpDescription;
+ m_dvpFileName = other.m_dvpFileName;
+ m_dvpLineNumber = other.m_dvpLineNumber;
+#endif
return *this;
}
@@ -89,7 +97,12 @@ struct STDAllocator
T* allocate(std::size_t count)
{
- return reinterpret_cast<T*>( m_Allocator.Allocate(count * sizeof(T), m_dbgDescription, m_dbgFileName, m_dbgLineNumber ) );
+#ifndef DEVELOPMENT
+ static constexpr char* m_dvpDescription = "<Unavailable in release build>";
+ static constexpr char* m_dvpFileName = "<Unavailable in release build>";
+ static constexpr Int32 m_dvpLineNumber = -1;
+#endif
+ return reinterpret_cast<T*>( m_Allocator.Allocate(count * sizeof(T), m_dvpDescription, m_dvpFileName, m_dvpLineNumber ) );
}
void deallocate(T* p, std::size_t count)
@@ -115,9 +128,11 @@ struct STDAllocator
}
AllocatorType &m_Allocator;
- const Char* m_dbgDescription;
- const Char* m_dbgFileName;
- Int32 m_dbgLineNumber;
+#ifdef DEVELOPMENT
+ const Char* const m_dvpDescription;
+ const Char* const m_dvpFileName;
+ Int32 const m_dvpLineNumber;
+#endif
};
#define STD_ALLOCATOR(Type, AllocatorType, Allocator, Description) STDAllocator<Type, AllocatorType>(Allocator, Description, __FILE__, __LINE__)