1
0
mirror of https://github.com/wolfpld/tracy synced 2025-04-28 20:23:51 +00:00

Optimize slab allocation.

This commit is contained in:
Bartosz Taudul 2020-02-23 19:43:00 +01:00
parent 085e1fd43f
commit 00d91cb9ab

View File

@ -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<typename T>
@ -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;