Free chunks in CACHED_CONTAINER only if they are really not needed.
This commit is contained in:
parent
702be4903f
commit
a9c3a1730b
|
@ -126,12 +126,8 @@ VERTEX* CACHED_CONTAINER::Allocate( unsigned int aSize )
|
||||||
if( m_itemSize + aSize > m_chunkSize )
|
if( m_itemSize + aSize > m_chunkSize )
|
||||||
{
|
{
|
||||||
// There is not enough space in the currently reserved chunk, so we have to resize it
|
// There is not enough space in the currently reserved chunk, so we have to resize it
|
||||||
|
m_chunkSize = reallocate( m_itemSize + aSize );
|
||||||
// Reserve a bigger memory chunk for the current item and
|
m_chunkOffset = m_item->GetOffset();
|
||||||
// make it multiple of 3 to store triangles
|
|
||||||
m_chunkSize = ( 2 * m_itemSize ) + aSize + ( 3 - aSize % 3 );
|
|
||||||
// Save the current size before reallocating
|
|
||||||
m_chunkOffset = reallocate( m_chunkSize );
|
|
||||||
|
|
||||||
if( m_chunkOffset > m_currentSize )
|
if( m_chunkOffset > m_currentSize )
|
||||||
{
|
{
|
||||||
|
@ -142,6 +138,7 @@ VERTEX* CACHED_CONTAINER::Allocate( unsigned int aSize )
|
||||||
|
|
||||||
VERTEX* reserved = &m_vertices[m_chunkOffset + m_itemSize];
|
VERTEX* reserved = &m_vertices[m_chunkOffset + m_itemSize];
|
||||||
m_itemSize += aSize;
|
m_itemSize += aSize;
|
||||||
|
|
||||||
// Now the item officially possesses the memory chunk
|
// Now the item officially possesses the memory chunk
|
||||||
m_item->setSize( m_itemSize );
|
m_item->setSize( m_itemSize );
|
||||||
|
|
||||||
|
@ -340,19 +337,10 @@ unsigned int CACHED_CONTAINER::reallocate( unsigned int aSize )
|
||||||
|
|
||||||
// Remove the allocated chunk from the free space pool
|
// Remove the allocated chunk from the free space pool
|
||||||
m_freeChunks.erase( newChunk );
|
m_freeChunks.erase( newChunk );
|
||||||
|
m_freeSpace -= newChunkSize;
|
||||||
// If there is some space left, return it to the pool - add an entry for it
|
|
||||||
if( newChunkSize > aSize )
|
|
||||||
{
|
|
||||||
m_freeChunks.insert( CHUNK( newChunkSize - aSize, newChunkOffset + aSize ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
m_freeSpace -= aSize;
|
|
||||||
// mergeFreeChunks(); // veery slow and buggy
|
|
||||||
|
|
||||||
m_item->setOffset( newChunkOffset );
|
m_item->setOffset( newChunkOffset );
|
||||||
|
|
||||||
return newChunkOffset;
|
return newChunkSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -124,10 +124,11 @@ protected:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function reallocate()
|
* Function reallocate()
|
||||||
* resizes the chunk that stores the current item to the given size.
|
* resizes the chunk that stores the current item to the given size. The current item has
|
||||||
|
* its offset adjusted after the call.
|
||||||
*
|
*
|
||||||
* @param aSize is the number of vertices to be stored.
|
* @param aSize is the number of vertices to be stored.
|
||||||
* @return offset of the new chunk.
|
* @return size of the new chunk (might be bigger than requested).
|
||||||
*/
|
*/
|
||||||
unsigned int reallocate( unsigned int aSize );
|
unsigned int reallocate( unsigned int aSize );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue