ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib::monomem::TLocalAllocator< TCapacityInKB, TAllocator > Class Template Reference

Description:

template<size_t TCapacityInKB, typename TAllocator = lang::HeapAllocator>
class alib::monomem::TLocalAllocator< TCapacityInKB, TAllocator >

A mono allocator, that incorporates a member of templated size TCapacityInKB, which is used as the initial buffer for allocation. The class is intended to be instantiated by local variables, hence using stack memory.
When the initial buffer is exhausted, further buffers will be heap allocated.

Note that the usual type alias given in namespace alib, in this case misses the leading "T", and is given with LocalAllocator. Besides that, further aliases that denote specific stack sizes are provided with LocalAllocator1K, LocalAllocator2K, LocalAllocator4K, LocalAllocator8K, LocalAllocator16K, LocalAllocator32K, and LocalAllocator64K.

See also
Chapter 3.3 Class LocalAllocator of the Programmer's Manual of this ALib Camp.
Template Parameters
TCapacityInKBThe size of the internal buffer in kilobytes.
TAllocatorThe allocator type that parent TMonoAllocator should be chained to.
Defaults to HeapAllocator.

Definition at line 35 of file localallocator.inl.

Inheritance diagram for alib::monomem::TLocalAllocator< TCapacityInKB, TAllocator >:
[legend]
Collaboration diagram for alib::monomem::TLocalAllocator< TCapacityInKB, TAllocator >:
[legend]

Public Method Index:

 TLocalAllocator (TAllocator &pAllocator, unsigned int pBufferGrowthInPercent=200)
 
 TLocalAllocator (unsigned int pBufferGrowthInPercent=200)
 
 ~TLocalAllocator ()
 Destructor. Calls MonoAllocator::destructWithExternalBuffer.
 
MonoAllocatorAsMonoAllocator ()
 
- Public Method Index: inherited from alib::monomem::TMonoAllocator< lang::HeapAllocator >
 TMonoAllocator (const char *dbgName, detail::Buffer *pInitialBuffer, size_t pInitialBufferSizeInKB, unsigned int pBufferGrowthInPercent=200)
 
 TMonoAllocator (const char *dbgName, detail::Buffer *pInitialBuffer, size_t pInitialBufferSizeInKB, unsigned int pBufferGrowthInPercent=200)
 
 TMonoAllocator (const char *dbgName, lang::HeapAllocator &pAllocator, detail::Buffer *pInitialBuffer, size_t pInitialBufferSizeInKB, unsigned int pBufferGrowthInPercent=200)
 
 TMonoAllocator (const char *dbgName, lang::HeapAllocator &pAllocator, detail::Buffer *pInitialBuffer, size_t pInitialBufferSizeInKB, unsigned int pBufferGrowthInPercent=200)
 
ALIB_DLL TMonoAllocator (const char *dbgName, lang::HeapAllocator &pAllocator, size_t pInitialBufferSizeInKB, unsigned int pBufferGrowthInPercent=200)
 
ALIB_DLL TMonoAllocator (const char *dbgName, lang::HeapAllocator &pAllocator, size_t pInitialBufferSizeInKB, unsigned int pBufferGrowthInPercent=200)
 
 TMonoAllocator (const char *dbgName, size_t pInitialBufferSizeInKB, unsigned int pBufferGrowthInPercent=200)
 
 TMonoAllocator (const char *dbgName, size_t pInitialBufferSizeInKB, unsigned int pBufferGrowthInPercent=200)
 
 TMonoAllocator (const char *dbgName, std::nullptr_t) noexcept
 
 TMonoAllocator (const char *dbgName, std::nullptr_t) noexcept
 
 TMonoAllocator (const TMonoAllocator &)=delete
 Not copyable.
 
 TMonoAllocator (const TMonoAllocator &)=delete
 Not copyable.
 
 TMonoAllocator (TMonoAllocator &&)=delete
 Not movable.
 
 TMonoAllocator (TMonoAllocator &&)=delete
 Not movable.
 
ALIB_DLL ~TMonoAllocator ()
 Destructor. Disposes all memory allocated with ChainedAllocator.
 
ALIB_DLL ~TMonoAllocator ()
 Destructor. Disposes all memory allocated with ChainedAllocator.
 
void * allocate (size_t size, size_t alignment)
 
void * reallocate (void *mem, size_t oldSize, size_t newSize, size_t alignment)
 
void free (void *mem, size_t size) const
 
void dbgAcknowledgeIncreasedAllocSize (void *, TSize) const
 
lang::AllocatorInterface< TMonoAllocatoroperator() ()
 
constexpr bool allowsMemSplit () noexcept
 
void * allocate (size_t size, size_t alignment)
 
void * reallocate (void *mem, size_t oldSize, size_t newSize, size_t alignment)
 
void free (void *mem, size_t size) const
 
void dbgAcknowledgeIncreasedAllocSize (void *, TSize) const
 
lang::AllocatorInterface< TMonoAllocatoroperator() ()
 
constexpr bool allowsMemSplit () noexcept
 
Snapshot TakeSnapshot ()
 
ALIB_DLL void Reset (Snapshot snapshot=Snapshot())
 
void Reset (size_t firstObjectSize, size_t firstObjectAlignment)
 
Snapshot TakeSnapshot ()
 
ALIB_DLL void Reset (Snapshot snapshot=Snapshot())
 
void Reset (size_t firstObjectSize, size_t firstObjectAlignment)
 
ALIB_DLL void GetStatistics (Statistics &result)
 
void DbgLock (bool onOff) noexcept
 
detail::BufferDbgGetBuffer () noexcept
 
const detail::BufferDbgGetBuffer () const noexcept
 
void dbgCheckMemory (void *mem, TSize size)
 
const DbgStatisticsDbgGetStatistics () const
 
ALIB_DLL void GetStatistics (Statistics &result)
 
void DbgLock (bool onOff) noexcept
 
detail::BufferDbgGetBuffer () noexcept
 
const detail::BufferDbgGetBuffer () const noexcept
 
void dbgCheckMemory (void *mem, TSize size)
 
const DbgStatisticsDbgGetStatistics () const
 
ALIB_DLL void destructWithExternalBuffer ()
 
bool IsInitialized () const noexcept
 
ALIB_DLL void destructWithExternalBuffer ()
 
bool IsInitialized () const noexcept
 
- Public Method Index: inherited from alib::lang::AllocatorMember< lang::HeapAllocator >
 AllocatorMember ()=delete
 Deleted default constructor. (The allocator has to be given with construction)
 
 AllocatorMember (lang::HeapAllocator &pAllocator) noexcept
 
AllocatorInterface< lang::HeapAllocatorAI () const noexcept
 
lang::HeapAllocatorGetAllocator () const noexcept
 

Protected Type Index:

using base = TMonoAllocator<TAllocator>
 Shortcut to our base type.
 
- Protected Type Index: inherited from alib::monomem::TMonoAllocator< lang::HeapAllocator >
using allocMember
 The allocator type that TAllocator specifies.
 

Protected Field Index:

void * localMemory [TCapacityInKB *1024/sizeof(void *)]
 Internal memory passed as a first buffer to base class MonoAllocator.
 
- Protected Field Index: inherited from alib::monomem::TMonoAllocator< lang::HeapAllocator >
detail::Bufferbuffer
 The actual buffer. Contains a link to previously allocated buffers.
 
detail::Bufferbuffer
 The actual buffer. Contains a link to previously allocated buffers.
 
unsigned int bufferGrowthInPercent
 
unsigned int bufferGrowthInPercent
 
bool dbgLock
 
bool dbgLock
 
DbgStatistics dbgStats
 
DbgStatistics dbgStats
 
size_t nextBuffersUsableSize
 
size_t nextBuffersUsableSize
 
detail::Bufferrecyclables
 The list of buffers that are to be recycled.
 
detail::Bufferrecyclables
 The list of buffers that are to be recycled.
 
- Protected Field Index: inherited from alib::lang::AllocatorMember< lang::HeapAllocator >
lang::HeapAllocatorallocator
 A reference to the allocator.
 

Additional Inherited Members

- Public Type Index: inherited from alib::monomem::TMonoAllocator< lang::HeapAllocator >
using ChainedAllocator
 
- Public Type Index: inherited from alib::lang::AllocatorMember< lang::HeapAllocator >
using AllocatorType
 Exposes the allocator type.
 
- Public Static Field Index: inherited from alib::monomem::TMonoAllocator< lang::HeapAllocator >
static constexpr size_t MAX_ALIGNMENT
 
static constexpr size_t MAX_ALIGNMENT
 
static constexpr size_t MIN_ALIGNMENT
 
static constexpr size_t MIN_ALIGNMENT
 
static ALIB_DLL TMonoAllocatorCreate (const char *dbgName, lang::HeapAllocator &pAllocator, size_t initialBufferSizeInKB, unsigned int bufferGrowthInPercent=200)
 
static TMonoAllocatorCreate (const char *dbgName, size_t initialBufferSizeInKB, unsigned int bufferGrowthInPercent=200)
 
static ALIB_DLL TMonoAllocatorCreate (const char *dbgName, lang::HeapAllocator &pAllocator, size_t initialBufferSizeInKB, unsigned int bufferGrowthInPercent=200)
 
static TMonoAllocatorCreate (const char *dbgName, size_t initialBufferSizeInKB, unsigned int bufferGrowthInPercent=200)
 
- Public Field Index: inherited from alib::monomem::TMonoAllocator< lang::HeapAllocator >
lang::Placeholder< lang::DbgCriticalSectionsDbgCriticalSectionsPH
 
lang::Placeholder< lang::DbgCriticalSectionsDbgCriticalSectionsPH
 
const char * DbgName
 
const char * DbgName
 
- Protected Method Index: inherited from alib::monomem::TMonoAllocator< lang::HeapAllocator >
ALIB_DLL char * nextBuffer (size_t size, size_t alignment)
 
ALIB_DLL char * nextBuffer (size_t size, size_t alignment)
 

Type Definition Details:

◆ base

template<size_t TCapacityInKB, typename TAllocator = lang::HeapAllocator>
using alib::monomem::TLocalAllocator< TCapacityInKB, TAllocator >::base = TMonoAllocator<TAllocator>
protected

Shortcut to our base type.

Definition at line 39 of file localallocator.inl.

Field Details:

◆ localMemory

template<size_t TCapacityInKB, typename TAllocator = lang::HeapAllocator>
void* alib::monomem::TLocalAllocator< TCapacityInKB, TAllocator >::localMemory[TCapacityInKB *1024/sizeof(void *)]
protected

Internal memory passed as a first buffer to base class MonoAllocator.

Definition at line 42 of file localallocator.inl.

Constructor(s) / Destructor Details:

◆ TLocalAllocator() [1/2]

template<size_t TCapacityInKB, typename TAllocator = lang::HeapAllocator>
alib::monomem::TLocalAllocator< TCapacityInKB, TAllocator >::TLocalAllocator ( unsigned int pBufferGrowthInPercent = 200)
inline

Default constructor.

Parameters
pBufferGrowthInPercentOptional growth factor in percent, applied to each allocation of a next buffer size in respect to its previous size. Defaults to 200, which doubles buffer size with each next internal buffer allocation.

Definition at line 50 of file localallocator.inl.

◆ TLocalAllocator() [2/2]

template<size_t TCapacityInKB, typename TAllocator = lang::HeapAllocator>
alib::monomem::TLocalAllocator< TCapacityInKB, TAllocator >::TLocalAllocator ( TAllocator & pAllocator,
unsigned int pBufferGrowthInPercent = 200 )
inline

Constructor that accepts a different underlying allocator

Parameters
pAllocatorThe allocator to use for allocation of additional buffers.
pBufferGrowthInPercentOptional growth factor in percent, applied to each allocation of a next buffer size in respect to its previous size. Defaults to 200, which doubles buffer size with each next internal buffer allocation.

Definition at line 62 of file localallocator.inl.

◆ ~TLocalAllocator()

template<size_t TCapacityInKB, typename TAllocator = lang::HeapAllocator>
alib::monomem::TLocalAllocator< TCapacityInKB, TAllocator >::~TLocalAllocator ( )
inline

Destructor. Calls MonoAllocator::destructWithExternalBuffer.

Definition at line 70 of file localallocator.inl.

Method Details:

◆ AsMonoAllocator()

template<size_t TCapacityInKB, typename TAllocator = lang::HeapAllocator>
MonoAllocator & alib::monomem::TLocalAllocator< TCapacityInKB, TAllocator >::AsMonoAllocator ( )
inline

Convenience method that returns *this statically cast to base type MonoAllocator. This is primarily needed in situations where overload resolution of methods fails, if not exactly this base type is given. A prominent sample for this is the constructor of type AStringMA.

Returns
A reference to *this as its base type.

Definition at line 81 of file localallocator.inl.


The documentation for this class was generated from the following file: