Put some code within Loki::Private namespace.
git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@1071 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
1b9364270f
commit
b82b7f94aa
2 changed files with 47 additions and 27 deletions
|
@ -75,7 +75,10 @@ namespace Loki
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class FixedAllocator;
|
namespace Private
|
||||||
|
{
|
||||||
|
class FixedAllocator;
|
||||||
|
}; // end namespace Private
|
||||||
|
|
||||||
/** @class SmallObjAllocator
|
/** @class SmallObjAllocator
|
||||||
@ingroup SmallObjectGroupInternal
|
@ingroup SmallObjectGroupInternal
|
||||||
|
@ -92,8 +95,8 @@ namespace Loki
|
||||||
@param maxObjectSize Max # of bytes which this may allocate.
|
@param maxObjectSize Max # of bytes which this may allocate.
|
||||||
@param objectAlignSize # of bytes between alignment boundaries.
|
@param objectAlignSize # of bytes between alignment boundaries.
|
||||||
*/
|
*/
|
||||||
SmallObjAllocator( std::size_t pageSize, std::size_t maxObjectSize,
|
SmallObjAllocator( ::std::size_t pageSize, ::std::size_t maxObjectSize,
|
||||||
std::size_t objectAlignSize );
|
::std::size_t objectAlignSize );
|
||||||
|
|
||||||
/** Destructor releases all blocks, all Chunks, and FixedAllocator's.
|
/** Destructor releases all blocks, all Chunks, and FixedAllocator's.
|
||||||
Any outstanding blocks are unavailable, and should not be used after
|
Any outstanding blocks are unavailable, and should not be used after
|
||||||
|
@ -150,7 +153,7 @@ namespace Loki
|
||||||
void Deallocate( void * p );
|
void Deallocate( void * p );
|
||||||
|
|
||||||
/// Returns max # of bytes which this can allocate.
|
/// Returns max # of bytes which this can allocate.
|
||||||
inline std::size_t GetMaxObjectSize() const
|
inline ::std::size_t GetMaxObjectSize() const
|
||||||
{ return maxSmallObjectSize_; }
|
{ return maxSmallObjectSize_; }
|
||||||
|
|
||||||
/// Returns # of bytes between allocation boundaries.
|
/// Returns # of bytes between allocation boundaries.
|
||||||
|
@ -184,16 +187,15 @@ namespace Loki
|
||||||
SmallObjAllocator & operator = ( const SmallObjAllocator & );
|
SmallObjAllocator & operator = ( const SmallObjAllocator & );
|
||||||
|
|
||||||
/// Pointer to array of fixed-size allocators.
|
/// Pointer to array of fixed-size allocators.
|
||||||
Loki::FixedAllocator * pool_;
|
::Loki::Private::FixedAllocator * pool_;
|
||||||
|
|
||||||
/// Largest object size supported by allocators.
|
/// Largest object size supported by allocators.
|
||||||
const std::size_t maxSmallObjectSize_;
|
const ::std::size_t maxSmallObjectSize_;
|
||||||
|
|
||||||
/// Size of alignment boundaries.
|
/// Size of alignment boundaries.
|
||||||
const std::size_t objectAlignSize_;
|
const ::std::size_t objectAlignSize_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/** @class AllocatorSingleton
|
/** @class AllocatorSingleton
|
||||||
@ingroup SmallObjectGroupInternal
|
@ingroup SmallObjectGroupInternal
|
||||||
This template class is derived from
|
This template class is derived from
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
// $Id$
|
// $Id$
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <loki/SmallObj.h>
|
#include <loki/SmallObj.h>
|
||||||
|
|
||||||
|
@ -32,12 +33,16 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined( nullptr )
|
#if !defined( nullptr )
|
||||||
#define nullptr
|
#define nullptr 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace Loki
|
namespace Loki
|
||||||
{
|
{
|
||||||
|
namespace Private
|
||||||
|
{
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
/** @struct Chunk
|
/** @struct Chunk
|
||||||
@ingroup SmallObjectGroupInternal
|
@ingroup SmallObjectGroupInternal
|
||||||
|
@ -302,6 +307,26 @@ namespace Loki
|
||||||
unsigned char FixedAllocator::MinObjectsPerChunk_ = 8;
|
unsigned char FixedAllocator::MinObjectsPerChunk_ = 8;
|
||||||
unsigned char FixedAllocator::MaxObjectsPerChunk_ = UCHAR_MAX;
|
unsigned char FixedAllocator::MaxObjectsPerChunk_ = UCHAR_MAX;
|
||||||
|
|
||||||
|
/** @ingroup SmallObjectGroupInternal
|
||||||
|
Calls the default allocator when SmallObjAllocator decides not to handle a
|
||||||
|
request. SmallObjAllocator calls this if the number of bytes is bigger than
|
||||||
|
the size which can be handled by any FixedAllocator.
|
||||||
|
@param numBytes number of bytes
|
||||||
|
@param doThrow True if this function should throw an exception, or false if it
|
||||||
|
should indicate failure by returning a nullptr pointer.
|
||||||
|
*/
|
||||||
|
void * DefaultAllocator( std::size_t numBytes, bool doThrow );
|
||||||
|
|
||||||
|
/** @ingroup SmallObjectGroupInternal
|
||||||
|
Calls default deallocator when SmallObjAllocator decides not to handle a
|
||||||
|
request. The default deallocator could be the global delete operator or the
|
||||||
|
free function. The free function is the preferred default deallocator since
|
||||||
|
it matches malloc which is the preferred default allocator. SmallObjAllocator
|
||||||
|
will call this if an address was not found among any of its own blocks.
|
||||||
|
*/
|
||||||
|
void DefaultDeallocator( void * p );
|
||||||
|
|
||||||
|
|
||||||
// Chunk::Init ----------------------------------------------------------------
|
// Chunk::Init ----------------------------------------------------------------
|
||||||
|
|
||||||
bool Chunk::Init( std::size_t blockSize, unsigned char blocks )
|
bool Chunk::Init( std::size_t blockSize, unsigned char blocks )
|
||||||
|
@ -1024,14 +1049,7 @@ inline std::size_t GetOffset( std::size_t numBytes, std::size_t alignment )
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultAllocator -----------------------------------------------------------
|
// DefaultAllocator -----------------------------------------------------------
|
||||||
/** @ingroup SmallObjectGroupInternal
|
|
||||||
Calls the default allocator when SmallObjAllocator decides not to handle a
|
|
||||||
request. SmallObjAllocator calls this if the number of bytes is bigger than
|
|
||||||
the size which can be handled by any FixedAllocator.
|
|
||||||
@param numBytes number of bytes
|
|
||||||
@param doThrow True if this function should throw an exception, or false if it
|
|
||||||
should indicate failure by returning a nullptr pointer.
|
|
||||||
*/
|
|
||||||
void * DefaultAllocator( std::size_t numBytes, bool doThrow )
|
void * DefaultAllocator( std::size_t numBytes, bool doThrow )
|
||||||
{
|
{
|
||||||
#ifdef USE_NEW_TO_ALLOCATE
|
#ifdef USE_NEW_TO_ALLOCATE
|
||||||
|
@ -1046,13 +1064,7 @@ void * DefaultAllocator( std::size_t numBytes, bool doThrow )
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultDeallocator ---------------------------------------------------------
|
// DefaultDeallocator ---------------------------------------------------------
|
||||||
/** @ingroup SmallObjectGroupInternal
|
|
||||||
Calls default deallocator when SmallObjAllocator decides not to handle a
|
|
||||||
request. The default deallocator could be the global delete operator or the
|
|
||||||
free function. The free function is the preferred default deallocator since
|
|
||||||
it matches malloc which is the preferred default allocator. SmallObjAllocator
|
|
||||||
will call this if an address was not found among any of its own blocks.
|
|
||||||
*/
|
|
||||||
void DefaultDeallocator( void * p )
|
void DefaultDeallocator( void * p )
|
||||||
{
|
{
|
||||||
#ifdef USE_NEW_TO_ALLOCATE
|
#ifdef USE_NEW_TO_ALLOCATE
|
||||||
|
@ -1062,6 +1074,13 @@ void DefaultDeallocator( void * p )
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
}; // end namespace Private
|
||||||
|
|
||||||
|
using namespace ::Loki::Private;
|
||||||
|
|
||||||
|
|
||||||
// SmallObjAllocator::SmallObjAllocator ---------------------------------------
|
// SmallObjAllocator::SmallObjAllocator ---------------------------------------
|
||||||
|
|
||||||
SmallObjAllocator::SmallObjAllocator( std::size_t pageSize,
|
SmallObjAllocator::SmallObjAllocator( std::size_t pageSize,
|
||||||
|
@ -1176,8 +1195,8 @@ void SmallObjAllocator::Deallocate( void * p )
|
||||||
{
|
{
|
||||||
if ( nullptr == p ) return;
|
if ( nullptr == p ) return;
|
||||||
assert( nullptr != pool_ );
|
assert( nullptr != pool_ );
|
||||||
FixedAllocator * pAllocator = nullptr;
|
::Loki::Private::FixedAllocator * pAllocator = nullptr;
|
||||||
const std::size_t allocCount = GetOffset( GetMaxObjectSize(), GetAlignment() );
|
const std::size_t allocCount = ::Loki::Private::GetOffset( GetMaxObjectSize(), GetAlignment() );
|
||||||
Chunk * chunk = nullptr;
|
Chunk * chunk = nullptr;
|
||||||
|
|
||||||
for ( std::size_t ii = 0; ii < allocCount; ++ii )
|
for ( std::size_t ii = 0; ii < allocCount; ++ii )
|
||||||
|
@ -1230,4 +1249,3 @@ bool SmallObjAllocator::IsCorrupt( void ) const
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end namespace Loki
|
} // end namespace Loki
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue