mirror of
https://github.com/wolfpld/tracy
synced 2025-04-29 04:23:51 +00:00
Optimize slab allocation.
This commit is contained in:
parent
085e1fd43f
commit
00d91cb9ab
@ -34,11 +34,18 @@ public:
|
|||||||
tracy_force_inline void* AllocRaw( size_t size )
|
tracy_force_inline void* AllocRaw( size_t size )
|
||||||
{
|
{
|
||||||
assert( size <= BlockSize );
|
assert( size <= BlockSize );
|
||||||
if( m_offset + size > BlockSize ) DoAlloc();
|
const auto offset = m_offset;
|
||||||
void* ret = m_ptr + m_offset;
|
if( offset + size > BlockSize )
|
||||||
|
{
|
||||||
|
return DoAlloc( size );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
void* ret = m_ptr + offset;
|
||||||
m_offset += size;
|
m_offset += size;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
tracy_force_inline T* AllocInit()
|
tracy_force_inline T* AllocInit()
|
||||||
@ -83,18 +90,16 @@ public:
|
|||||||
|
|
||||||
tracy_force_inline void* AllocBig( size_t size )
|
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;
|
m_offset += size;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
else if( size <= BlockSize && BlockSize - m_offset <= 1024 )
|
else if( size <= BlockSize && BlockSize - offset <= 1024 )
|
||||||
{
|
{
|
||||||
DoAlloc();
|
return DoAlloc( size );
|
||||||
void* ret = m_ptr + m_offset;
|
|
||||||
m_offset += size;
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -130,13 +135,15 @@ public:
|
|||||||
Slab& operator=( Slab&& ) = delete;
|
Slab& operator=( Slab&& ) = delete;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void DoAlloc()
|
void* DoAlloc( uint32_t willUseBytes )
|
||||||
{
|
{
|
||||||
m_ptr = new char[BlockSize];
|
auto ptr = new char[BlockSize];
|
||||||
m_offset = 0;
|
m_ptr = ptr;
|
||||||
|
m_offset = willUseBytes;
|
||||||
m_buffer.emplace_back( m_ptr );
|
m_buffer.emplace_back( m_ptr );
|
||||||
memUsage += BlockSize;
|
memUsage += BlockSize;
|
||||||
m_usage += BlockSize;
|
m_usage += BlockSize;
|
||||||
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* m_ptr;
|
char* m_ptr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user