diff --git a/include/loki/SmallObj.h b/include/loki/SmallObj.h index dc77827..2162ff4 100644 --- a/include/loki/SmallObj.h +++ b/include/loki/SmallObj.h @@ -75,7 +75,10 @@ namespace Loki } - class FixedAllocator; + namespace Private + { + class FixedAllocator; + }; // end namespace Private /** @class SmallObjAllocator @ingroup SmallObjectGroupInternal @@ -92,8 +95,8 @@ namespace Loki @param maxObjectSize Max # of bytes which this may allocate. @param objectAlignSize # of bytes between alignment boundaries. */ - SmallObjAllocator( std::size_t pageSize, std::size_t maxObjectSize, - std::size_t objectAlignSize ); + SmallObjAllocator( ::std::size_t pageSize, ::std::size_t maxObjectSize, + ::std::size_t objectAlignSize ); /** Destructor releases all blocks, all Chunks, and FixedAllocator's. Any outstanding blocks are unavailable, and should not be used after @@ -150,7 +153,7 @@ namespace Loki void Deallocate( void * p ); /// Returns max # of bytes which this can allocate. - inline std::size_t GetMaxObjectSize() const + inline ::std::size_t GetMaxObjectSize() const { return maxSmallObjectSize_; } /// Returns # of bytes between allocation boundaries. @@ -184,16 +187,15 @@ namespace Loki SmallObjAllocator & operator = ( const SmallObjAllocator & ); /// Pointer to array of fixed-size allocators. - Loki::FixedAllocator * pool_; + ::Loki::Private::FixedAllocator * pool_; /// Largest object size supported by allocators. - const std::size_t maxSmallObjectSize_; + const ::std::size_t maxSmallObjectSize_; /// Size of alignment boundaries. - const std::size_t objectAlignSize_; + const ::std::size_t objectAlignSize_; }; - /** @class AllocatorSingleton @ingroup SmallObjectGroupInternal This template class is derived from diff --git a/src/SmallObj.cpp b/src/SmallObj.cpp index e0080d9..3fcc7f5 100644 --- a/src/SmallObj.cpp +++ b/src/SmallObj.cpp @@ -15,6 +15,7 @@ // $Id$ +// ---------------------------------------------------------------------------- #include @@ -32,12 +33,16 @@ #endif #if !defined( nullptr ) - #define nullptr + #define nullptr 0 #endif namespace Loki { +namespace Private +{ + +// ---------------------------------------------------------------------------- /** @struct Chunk @ingroup SmallObjectGroupInternal @@ -302,6 +307,26 @@ namespace Loki unsigned char FixedAllocator::MinObjectsPerChunk_ = 8; 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 ---------------------------------------------------------------- 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 ----------------------------------------------------------- -/** @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 ) { #ifdef USE_NEW_TO_ALLOCATE @@ -1046,13 +1064,7 @@ void * DefaultAllocator( std::size_t numBytes, bool doThrow ) } // 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 ) { #ifdef USE_NEW_TO_ALLOCATE @@ -1062,6 +1074,13 @@ void DefaultDeallocator( void * p ) #endif } +// ---------------------------------------------------------------------------- + +}; // end namespace Private + +using namespace ::Loki::Private; + + // SmallObjAllocator::SmallObjAllocator --------------------------------------- SmallObjAllocator::SmallObjAllocator( std::size_t pageSize, @@ -1176,8 +1195,8 @@ void SmallObjAllocator::Deallocate( void * p ) { if ( nullptr == p ) return; assert( nullptr != pool_ ); - FixedAllocator * pAllocator = nullptr; - const std::size_t allocCount = GetOffset( GetMaxObjectSize(), GetAlignment() ); + ::Loki::Private::FixedAllocator * pAllocator = nullptr; + const std::size_t allocCount = ::Loki::Private::GetOffset( GetMaxObjectSize(), GetAlignment() ); Chunk * chunk = nullptr; for ( std::size_t ii = 0; ii < allocCount; ++ii ) @@ -1230,4 +1249,3 @@ bool SmallObjAllocator::IsCorrupt( void ) const } } // end namespace Loki -