From ff51bc498f3411348227d326f784d3082616beb2 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sat, 8 Sep 2018 20:47:11 -0700 Subject: Fixed https://github.com/DiligentGraphics/DiligentCore/issues/31 (Remove debug info from STDAllocator in release build) --- Common/interface/RefCountedObjectImpl.h | 42 ++++++++++++++++--------- Common/interface/STDAllocator.h | 55 +++++++++++++++++++++------------ 2 files changed, 62 insertions(+), 35 deletions(-) (limited to 'Common/interface') 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 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 = ""; + static constexpr char* m_dvpFileName = ""; + 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(CtorArgs)... ); + pObj = new(*m_pAllocator, m_dvpDescription, m_dvpFileName, m_dvpLineNumber) ObjectType(pRefCounters, std::forward(CtorArgs)... ); else pObj = new ObjectType( pRefCounters, std::forward(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>(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 STDAllocator(const STDAllocator& 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 STDAllocator(STDAllocator&& 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( m_Allocator.Allocate(count * sizeof(T), m_dbgDescription, m_dbgFileName, m_dbgLineNumber ) ); +#ifndef DEVELOPMENT + static constexpr char* m_dvpDescription = ""; + static constexpr char* m_dvpFileName = ""; + static constexpr Int32 m_dvpLineNumber = -1; +#endif + return reinterpret_cast( 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(Allocator, Description, __FILE__, __LINE__) -- cgit v1.2.3