43#ifdef KICAD_GAL_PROFILE
50CACHED_CONTAINER::CACHED_CONTAINER(
unsigned int aSize ) :
64 assert( aItem !=
nullptr );
66 unsigned int itemSize = aItem->
GetSize();
77 assert(
m_item !=
nullptr );
101#if CACHED_CONTAINER_TEST > 1
109 assert(
m_item !=
nullptr );
116 unsigned int newSize = itemSize + aSize;
136#if CACHED_CONTAINER_TEST > 0
139#if CACHED_CONTAINER_TEST > 2
150 assert( aItem !=
nullptr );
168#if CACHED_CONTAINER_TEST > 0
197 for( ITEMS::iterator it =
m_items.begin(); it !=
m_items.end(); ++it )
198 ( *it )->setSize( 0 );
216 FREE_CHUNK_MAP::iterator newChunk =
m_freeChunks.lower_bound( aSize );
246 assert( newChunkSize >= aSize );
275 ITEMS::iterator it, it_end;
280 int itemOffset = item->GetOffset();
281 int itemSize = item->GetSize();
287 item->setOffset( newOffset );
290 newOffset += itemSize;
311#ifdef KICAD_GAL_PROFILE
316 std::list<CHUNK> freeChunks;
318 FREE_CHUNK_MAP::const_iterator it, it_end;
322 freeChunks.emplace_back( it->second, it->first );
328 std::list<CHUNK>::const_iterator itf, itf_end;
329 unsigned int offset = freeChunks.front().first;
330 unsigned int size = freeChunks.front().second;
331 freeChunks.pop_front();
333 for( itf = freeChunks.begin(), itf_end = freeChunks.end(); itf != itf_end; ++itf )
335 if( itf->first == offset + size )
354#if CACHED_CONTAINER_TEST > 0
365 m_freeChunks.insert( std::make_pair( aSize, aOffset ) );
382#ifdef KICAD_GAL_PROFILE
384 unsigned int freeSpace = 0;
385 FREE_CHUNK_MAP::iterator itf;
393 unsigned int used_space = 0;
397 used_space += ( *itr )->GetSize();
unsigned int m_chunkOffset
Maximal vertex index number stored in the container.
void addFreeChunk(unsigned int aOffset, unsigned int aSize)
Add a chunk marked as a free space.
int getChunkSize(const CHUNK &aChunk) const
Return the size of a chunk.
void mergeFreeChunks()
Look for consecutive free memory chunks and merges them, decreasing fragmentation of memory.
void showFreeChunks()
Debug & test functions.
VERTEX_ITEM * m_item
Properties of currently modified chunk & item.
FREE_CHUNK_MAP m_freeChunks
Stored VERTEX_ITEMs.
void defragment(VERTEX *aTarget)
Transfer all stored data to a new buffer, removing empty spaces between the data chunks in the contai...
virtual void FinishItem() override
Clean up after adding an item.
virtual void Delete(VERTEX_ITEM *aItem) override
Remove all data stored in the container and restores its original state.
unsigned int getChunkOffset(const CHUNK &aChunk) const
Return the offset of a chunk.
virtual VERTEX * Allocate(unsigned int aSize) override
Return allocated space for the requested number of vertices associated with the current item (set wit...
virtual void Clear() override
Remove all data stored in the container and restores its original state.
virtual bool defragmentResize(unsigned int aNewSize)=0
Remove empty spaces between chunks and optionally resizes the container.
virtual void SetItem(VERTEX_ITEM *aItem) override
Clean up after adding an item.
virtual bool IsMapped() const =0
Return true if vertex buffer is currently mapped.
ITEMS m_items
Currently modified item.
bool reallocate(unsigned int aSize)
Resize the chunk that stores the current item to the given size.
unsigned int m_initialSize
Actual storage memory.
unsigned int m_currentSize
Store the initial size, so it can be resized to this on Clear()
unsigned int m_freeSpace
Current container size, expressed in vertices.
unsigned int usedSpace() const
Return size of the used memory space.
bool m_dirty
Default initial size of a container (expressed in vertices)
void setSize(unsigned int aSize)
Set data size in the container.
void setOffset(unsigned int aOffset)
Set data offset in the container.
unsigned int GetOffset() const
Return data offset in the container.
unsigned int GetSize() const
Return information about number of vertices stored.
A small class to help profiling.
The Cairo implementation of the graphics abstraction layer.
static constexpr size_t VERTEX_SIZE
Class to handle an item held in a container.