diff --git a/server/TracySlab.hpp b/server/TracySlab.hpp index e0bf973a..17afce72 100644 --- a/server/TracySlab.hpp +++ b/server/TracySlab.hpp @@ -34,10 +34,17 @@ public: tracy_force_inline void* AllocRaw( size_t size ) { assert( size <= BlockSize ); - if( m_offset + size > BlockSize ) DoAlloc(); - void* ret = m_ptr + m_offset; - m_offset += size; - return ret; + const auto offset = m_offset; + if( offset + size > BlockSize ) + { + return DoAlloc( size ); + } + else + { + void* ret = m_ptr + offset; + m_offset += size; + return ret; + } } template @@ -83,18 +90,16 @@ public: tracy_force_inline void* AllocBig( size_t size ) { - if( m_offset + size <= BlockSize ) + const auto offset = m_offset; + if( offset + size <= BlockSize ) { - void* ret = m_ptr + m_offset; + void* ret = m_ptr + offset; m_offset += size; return ret; } - else if( size <= BlockSize && BlockSize - m_offset <= 1024 ) + else if( size <= BlockSize && BlockSize - offset <= 1024 ) { - DoAlloc(); - void* ret = m_ptr + m_offset; - m_offset += size; - return ret; + return DoAlloc( size ); } else { @@ -130,13 +135,15 @@ public: Slab& operator=( Slab&& ) = delete; private: - void DoAlloc() + void* DoAlloc( uint32_t willUseBytes ) { - m_ptr = new char[BlockSize]; - m_offset = 0; + auto ptr = new char[BlockSize]; + m_ptr = ptr; + m_offset = willUseBytes; m_buffer.emplace_back( m_ptr ); memUsage += BlockSize; m_usage += BlockSize; + return ptr; } char* m_ptr;