Changed Chunk list to double in size when adding new chunks instead of
just incrementing by 1. Changes linear operation into amortized constant time operation. git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@228 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
aa1b96d9c4
commit
d740b86c0a
1 changed files with 11 additions and 1 deletions
|
@ -261,10 +261,15 @@ bool FixedAllocator::MakeNewChunk( void )
|
||||||
bool allocated = false;
|
bool allocated = false;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
std::size_t size = chunks_.size();
|
||||||
// Calling chunks_.reserve *before* creating and initializing the new
|
// Calling chunks_.reserve *before* creating and initializing the new
|
||||||
// Chunk means that nothing is leaked by this function in case an
|
// Chunk means that nothing is leaked by this function in case an
|
||||||
// exception is thrown from reserve.
|
// exception is thrown from reserve.
|
||||||
chunks_.reserve( chunks_.size() + 1 );
|
if ( chunks_.capacity() == size )
|
||||||
|
{
|
||||||
|
if ( 0 == size ) size = 4;
|
||||||
|
chunks_.reserve( size * 2 );
|
||||||
|
}
|
||||||
Chunk newChunk;
|
Chunk newChunk;
|
||||||
allocated = newChunk.Init( blockSize_, numBlocks_ );
|
allocated = newChunk.Init( blockSize_, numBlocks_ );
|
||||||
if ( allocated )
|
if ( allocated )
|
||||||
|
@ -604,6 +609,11 @@ void SmallObjAllocator::Deallocate( void * p, std::size_t numBytes )
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// $Log$
|
// $Log$
|
||||||
|
// Revision 1.3 2005/09/01 22:15:47 rich_sposato
|
||||||
|
// Changed Chunk list to double in size when adding new chunks instead of
|
||||||
|
// just incrementing by 1. Changes linear operation into amortized constant
|
||||||
|
// time operation.
|
||||||
|
//
|
||||||
// Revision 1.2 2005/07/31 13:51:31 syntheticpp
|
// Revision 1.2 2005/07/31 13:51:31 syntheticpp
|
||||||
// replace old implementation with the ingeious from Rich Sposato
|
// replace old implementation with the ingeious from Rich Sposato
|
||||||
//
|
//
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue