remove tabs
git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@149 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
a113094a56
commit
718d2b32de
1 changed files with 43 additions and 43 deletions
|
@ -63,7 +63,7 @@ namespace Loki
|
||||||
// Internal functions
|
// Internal functions
|
||||||
void DoDeallocate(void* p);
|
void DoDeallocate(void* p);
|
||||||
|
|
||||||
bool MakeNewChunk( void );
|
bool MakeNewChunk( void );
|
||||||
|
|
||||||
Chunk * VicinityFind( void * p );
|
Chunk * VicinityFind( void * p );
|
||||||
|
|
||||||
|
@ -117,18 +117,18 @@ bool FixedAllocator::Chunk::Init( std::size_t blockSize, unsigned char blocks )
|
||||||
assert( allocSize / blockSize == blocks);
|
assert( allocSize / blockSize == blocks);
|
||||||
|
|
||||||
#ifdef USE_NEW_TO_ALLOCATE
|
#ifdef USE_NEW_TO_ALLOCATE
|
||||||
// If this new operator fails, it will throw, and the exception will get
|
// If this new operator fails, it will throw, and the exception will get
|
||||||
// caught one layer up.
|
// caught one layer up.
|
||||||
pData_ = new unsigned char[ allocSize ];
|
pData_ = new unsigned char[ allocSize ];
|
||||||
#else
|
#else
|
||||||
// malloc can't throw, so its only way to indicate an error is to return
|
// malloc can't throw, so its only way to indicate an error is to return
|
||||||
// a NULL pointer, so we have to check for that.
|
// a NULL pointer, so we have to check for that.
|
||||||
pData_ = static_cast< unsigned char * >( ::malloc( allocSize ) );
|
pData_ = static_cast< unsigned char * >( ::malloc( allocSize ) );
|
||||||
if ( NULL == pData_ ) return false;
|
if ( NULL == pData_ ) return false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Reset( blockSize, blocks );
|
Reset( blockSize, blocks );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -161,7 +161,7 @@ void FixedAllocator::Chunk::Reset(std::size_t blockSize, unsigned char blocks)
|
||||||
|
|
||||||
void FixedAllocator::Chunk::Release()
|
void FixedAllocator::Chunk::Release()
|
||||||
{
|
{
|
||||||
assert( NULL != pData_ );
|
assert( NULL != pData_ );
|
||||||
#ifdef USE_NEW_TO_ALLOCATE
|
#ifdef USE_NEW_TO_ALLOCATE
|
||||||
delete [] pData_;
|
delete [] pData_;
|
||||||
#else
|
#else
|
||||||
|
@ -258,27 +258,27 @@ void FixedAllocator::Initialize( std::size_t blockSize, std::size_t pageSize )
|
||||||
|
|
||||||
bool FixedAllocator::MakeNewChunk( void )
|
bool FixedAllocator::MakeNewChunk( void )
|
||||||
{
|
{
|
||||||
bool allocated = false;
|
bool allocated = false;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// 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 );
|
chunks_.reserve( chunks_.size() + 1 );
|
||||||
Chunk newChunk;
|
Chunk newChunk;
|
||||||
allocated = newChunk.Init( blockSize_, numBlocks_ );
|
allocated = newChunk.Init( blockSize_, numBlocks_ );
|
||||||
if ( allocated )
|
if ( allocated )
|
||||||
chunks_.push_back( newChunk );
|
chunks_.push_back( newChunk );
|
||||||
}
|
}
|
||||||
catch ( ... )
|
catch ( ... )
|
||||||
{
|
{
|
||||||
allocated = false;
|
allocated = false;
|
||||||
}
|
}
|
||||||
if ( !allocated ) return false;
|
if ( !allocated ) return false;
|
||||||
|
|
||||||
allocChunk_ = &chunks_.back();
|
allocChunk_ = &chunks_.back();
|
||||||
deallocChunk_ = &chunks_.front();
|
deallocChunk_ = &chunks_.front();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -304,8 +304,8 @@ void * FixedAllocator::Allocate( void )
|
||||||
{
|
{
|
||||||
if ( chunks_.end() == i )
|
if ( chunks_.end() == i )
|
||||||
{
|
{
|
||||||
if ( !MakeNewChunk() )
|
if ( !MakeNewChunk() )
|
||||||
return NULL;
|
return NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ( !i->IsFilled() )
|
if ( !i->IsFilled() )
|
||||||
|
@ -316,13 +316,13 @@ void * FixedAllocator::Allocate( void )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( allocChunk_ == emptyChunk_)
|
else if ( allocChunk_ == emptyChunk_)
|
||||||
// detach emptyChunk_ from allocChunk_, because after
|
// detach emptyChunk_ from allocChunk_, because after
|
||||||
// calling allocChunk_->Allocate(blockSize_); the chunk
|
// calling allocChunk_->Allocate(blockSize_); the chunk
|
||||||
// isn't any more empty
|
// isn't any more empty
|
||||||
emptyChunk_ = NULL;
|
emptyChunk_ = NULL;
|
||||||
|
|
||||||
void *place = allocChunk_->Allocate(blockSize_);
|
void *place = allocChunk_->Allocate(blockSize_);
|
||||||
|
|
||||||
assert( allocChunk_ != NULL );
|
assert( allocChunk_ != NULL );
|
||||||
assert( !allocChunk_->IsFilled() );
|
assert( !allocChunk_->IsFilled() );
|
||||||
|
@ -389,10 +389,10 @@ FixedAllocator::Chunk * FixedAllocator::VicinityFind( void * p )
|
||||||
{
|
{
|
||||||
if ( lo->HasBlock( pc, chunkLength ) ) return lo;
|
if ( lo->HasBlock( pc, chunkLength ) ) return lo;
|
||||||
if ( lo == loBound )
|
if ( lo == loBound )
|
||||||
{
|
{
|
||||||
lo = NULL;
|
lo = NULL;
|
||||||
if ( NULL == hi ) break;
|
if ( NULL == hi ) break;
|
||||||
}
|
}
|
||||||
else --lo;
|
else --lo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,10 +400,10 @@ FixedAllocator::Chunk * FixedAllocator::VicinityFind( void * p )
|
||||||
{
|
{
|
||||||
if ( hi->HasBlock( pc, chunkLength ) ) return hi;
|
if ( hi->HasBlock( pc, chunkLength ) ) return hi;
|
||||||
if ( ++hi == hiBound )
|
if ( ++hi == hiBound )
|
||||||
{
|
{
|
||||||
hi = NULL;
|
hi = NULL;
|
||||||
if ( NULL == lo ) break;
|
if ( NULL == lo ) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -551,7 +551,7 @@ void * SmallObjAllocator::Allocate( std::size_t numBytes, bool doThrow )
|
||||||
assert( allocator.BlockSize() >= numBytes );
|
assert( allocator.BlockSize() >= numBytes );
|
||||||
assert( allocator.BlockSize() < numBytes + GetAlignment() );
|
assert( allocator.BlockSize() < numBytes + GetAlignment() );
|
||||||
void * place = allocator.Allocate();
|
void * place = allocator.Allocate();
|
||||||
if ( ( NULL == place ) && doThrow )
|
if ( ( NULL == place ) && doThrow )
|
||||||
{
|
{
|
||||||
#if _MSC_VER
|
#if _MSC_VER
|
||||||
throw std::bad_alloc( "could not allocate small object" );
|
throw std::bad_alloc( "could not allocate small object" );
|
||||||
|
@ -560,7 +560,7 @@ void * SmallObjAllocator::Allocate( std::size_t numBytes, bool doThrow )
|
||||||
// so just throw the default-constructed exception.
|
// so just throw the default-constructed exception.
|
||||||
throw std::bad_alloc();
|
throw std::bad_alloc();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
return place;
|
return place;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue