43#ifdef KICAD_GAL_PROFILE
64 assert( aItem !=
nullptr );
66 unsigned int itemSize = aItem->
GetSize();
77 assert(
m_item !=
nullptr );
79 unsigned int itemSize =
m_item->GetSize();
85 int itemOffset =
m_item->GetOffset();
102#if CACHED_CONTAINER_TEST > 1
110 assert(
m_item !=
nullptr );
116 unsigned int itemSize =
m_item->GetSize();
117 unsigned int newSize = itemSize + aSize;
140 m_item->setSize( newSize );
145#if CACHED_CONTAINER_TEST > 0
148#if CACHED_CONTAINER_TEST > 2
159 assert( aItem !=
nullptr );
177#if CACHED_CONTAINER_TEST > 0
206 for( std::set<VERTEX_ITEM*>::iterator it =
m_items.begin(); it !=
m_items.end(); ++it )
207 ( *it )->setSize( 0 );
222 unsigned int itemSize =
m_item->GetSize();
225 FREE_CHUNK_MAP::iterator newChunk =
m_freeChunks.lower_bound( aSize );
255 assert( newChunkSize >= aSize );
291 std::set<VERTEX_ITEM*>::iterator it, it_end;
307 int itemOffset = item->GetOffset();
308 int itemSize = item->GetSize();
314 item->setOffset( newOffset );
317 newOffset += itemSize;
321 if(
m_item->GetSize() > 0 )
324 m_item->setOffset( newOffset );
333 __except( GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ? EXCEPTION_EXECUTE_HANDLER
334 : EXCEPTION_CONTINUE_SEARCH )
336 throw std::runtime_error(
337 "Access violation in defragment. This is usually an indicator of "
338 "system or GPU memory running low." );
353#ifdef KICAD_GAL_PROFILE
358 std::list<CHUNK> freeChunks;
360 FREE_CHUNK_MAP::const_iterator it, it_end;
364 freeChunks.emplace_back( it->second, it->first );
370 std::list<CHUNK>::const_iterator itf, itf_end;
371 unsigned int offset = freeChunks.front().first;
372 unsigned int size = freeChunks.front().second;
373 freeChunks.pop_front();
375 for( itf = freeChunks.begin(), itf_end = freeChunks.end(); itf != itf_end; ++itf )
377 if( itf->first == offset + size )
397#if CACHED_CONTAINER_TEST > 0
408 m_freeChunks.insert( std::make_pair( aSize, aOffset ) );
425#ifdef KICAD_GAL_PROFILE
427 unsigned int freeSpace = 0;
428 FREE_CHUNK_MAP::iterator itf;
436 unsigned int used_space = 0;
437 std::set<VERTEX_ITEM*>::iterator itr;
440 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.
std::set< VERTEX_ITEM * > m_items
Stored VERTEX_ITEMs.
void mergeFreeChunks()
Look for consecutive free memory chunks and merges them, decreasing fragmentation of memory.
void showFreeChunks()
Debug & test functions.
VERTEX_ITEM * m_item
Currently modified item.
FREE_CHUNK_MAP m_freeChunks
Store size & offset of free chunks.
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.
CACHED_CONTAINER(unsigned int aSize=DEFAULT_SIZE)
virtual bool IsMapped() const =0
Return true if vertex buffer is currently mapped.
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.
VERTEX_CONTAINER(unsigned int aSize=DEFAULT_SIZE)
bool m_dirty
Default initial size of a container (expressed in vertices)
void setSize(unsigned int aSize)
Set data size 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
wxString result
Test unit parsing edge cases and error handling.
Class to handle an item held in a container.