#ifndef __TRACYSLAB_HPP__ #define __TRACYSLAB_HPP__ #include #include namespace tracy { template class Slab { public: Slab() : m_ptr( new char[BlockSize] ) , m_buffer( { m_ptr } ) , m_offset( 0 ) {} ~Slab() { for( auto& v : m_buffer ) { delete[] v; } } void* Alloc( size_t size ) { assert( size <= BlockSize ); if( m_offset + size > BlockSize ) { m_ptr = new char[BlockSize]; m_offset = 0; m_buffer.emplace_back( m_ptr ); } void* ret = m_ptr + m_offset; m_offset += size; return ret; } template T* Alloc() { return new( Alloc( sizeof( T ) ) ) T; } void Unalloc( size_t size ) { assert( size <= m_offset ); m_offset -= size; } void Reset() { if( m_buffer.size() > 1 ) { for( int i=1; i m_buffer; }; } #endif