ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
TPoolAllocator< TAllocator, TAlignment > Class Template Reference

Description:

template<typename TAllocator, size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
class alib::monomem::TPoolAllocator< TAllocator, TAlignment >
Important Note
Please consult the Programmer's Manual of ALib module ALib Monomem for an introduction into the rather complex topic of monotonous and pool allocation and how to use this class.

This class implements the interface prototyped with Allocator. Whenever an object is freed with this allocator, the memory is stored in a stack for later re-use. This means, with allocations, first it is checked if a previously freed object of fitting size is available, and only if not, new memory is allocated. To implement this in a performant way (preferably with compile-time calculations), the following approach was taken:

  • The size of every allocation request is increased to the next higher power of 2 bound. For example, if a memory piece of 42 bytes is requested, a piece of size 64 bytes is returned.
  • For each allocation size, a simple stack (single directed linked list) is used to dispose and recycle memory.
  • The minimum allocation size is sizeof(void*), because for the recycling mechanism a pointer needs to be stored in the freed pool memory, when it is added to the internal "recycling stack".
  • This results in only 61 different allocation sizes (on a 64-bit machine).
  • A fixed alignment for all objects is used. This is also the maximum alignment allowed to pass to methods allocate and reallocate. Its value is defined by template parameter TAlignment, which defaults to what is given with compiler symbol ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT, which in turn defaults to alignof(uint64_t).
  • This approach results in only 61 different allocation sizes (on a 64-bit machine).

The consequences of this strategy are straight forward:

  • Using this allocator type requires disposing (free) every allocated piece of memory (which is in contrast to MonoAllocator).
  • This type is well suited for allocation scenarios, which release each object within a certain period of time, just to allocate new ones shortly afterward. A good use case example is given with module ALib ThreadModel: Here, request objects are pushed into priority queues, which are disposed after the request got processed. The objects are rather small and of different sizes. In complex server scenarios, it can become quickly millions of messages per second which are created and disposed.
  • A statistical average of 25% memory allocation overhead (waste) is taken into account with the use of this class.

Chapter 1.5 Recycling of the joint Programmer's Manual of modules ALib Containers and ALib Monomem provides an in-depth discussion of what is called "recycling" in this context. Several strategies are proposed with container types provided by module ALib Containers. From this perspective, this allocator could be seen as a "recycling proxy" in front of a MonoAllocator (or a different, chained allocator).

See also
Template Parameters
TAllocatorThe underlying allocator to use.
With type definition PoolAllocator,this is bound to type MonoAllocator.
With type definition PoolAllocatorHA,this is bound to type HeapAllocator.
For general information see chapter 8. Allocator Chaining of the Programmer's Manual.
TAlignmentThe fixed alignment to use. Corresponding method parameters are ignored.
Defaults to compiler symbol ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT, which in turn defaults to alignof(uint64_t).
It is statically asserted that this value is not higher than field MAX_ALIGNMENT of the given chained TAllocator and not smaller than alignof(void*).
See Chapter 11.1 Alignment of the Programmer's Manual of this module.

Definition at line 93 of file poolallocator.hpp.

#include <poolallocator.hpp>

Inheritance diagram for TPoolAllocator< TAllocator, TAlignment >:
[legend]
Collaboration diagram for TPoolAllocator< TAllocator, TAlignment >:
[legend]

Public Type Index:

using ChainedAllocator = TAllocator
 
- Public Type Index: inherited from AllocatorMember< TAllocator >
using AllocatorType = TAllocator
 Exposes the allocator type.
 

Public Static Field Index:

static constexpr size_t MAX_ALIGNMENT = TAlignment
 
static constexpr size_t MIN_ALIGNMENT = TAlignment
 
- Public Static Field Index: inherited from DbgCriticalSections
static ALIB_API const char * ASSERTION_FORMAT
 

Public Static Method Index:

Specific Interface (Static Methods)
static constexpr int AllocationInformationBitCount ()
 
template<typename T >
static constexpr short GetAllocInformation ()
 
template<typename TIntegral >
static constexpr short GetAllocInformation (TIntegral size)
 
static constexpr size_t GetAllocationSize (short allocInfo)
 

Public Field Index:

const char * DbgName
 
- Public Field Index: inherited from DbgCriticalSections
CallerInfo DCSAcq
 Source location of acquirement.
 
AssociatedLockDCSLock {nullptr}
 
const char * DCSName
 The name of this DCS. Used for debug-output.
 
std::atomic< int > DCSReaderCnt {0}
 Tracks enter/exit calls of readers.
 
CallerInfo DCSRel
 Source location of the last "reader" seen.
 
CallerInfo DCSSAcq
 Source location of acquirement.
 
CallerInfo DCSSRel
 Source location of the last "reader" seen.
 
std::atomic< int > DCSWriterCnt {0}
 Tracks enter/exit calls (including readers)
 
int DCSYieldOrSleepTimeInNS = -1
 

Public Method Index:

template<typename TEnableIf = allocMember, ATMP_T_IF(int, std::is_default_constructible< TEnableIf >::value) = 0>
 TPoolAllocator ()
 
ALIB_API TPoolAllocator (TAllocator &pAllocator)
 
ALIB_API ~TPoolAllocator ()
 Destructs this type.
 
lang::Allocator Implementation
void * allocate (size_t &size, size_t pAlignment)
 
void * reallocate (void *mem, size_t oldSize, size_t &newSize, size_t pAlignment)
 
void free (void *mem, size_t size)
 
template<typename TSize >
void dbgAcknowledgeIncreasedAllocSize (void *mem, TSize allocSize) const
 
constexpr bool allowsMemSplit () noexcept
 
lang::AllocatorInterface< TPoolAllocatoroperator() ()
 
Specific Interface
ALIB_API void * AllocateByAllocationInfo (int allocInfo)
 
void FreeByAllocationInfo (int allocInfo, void *mem)
 
void Reset ()
 
ALIB_API integer GetPoolSize (size_t size)
 
template<typename TSize >
void dbgCheckMemory (void *mem, TSize size)
 
int DbgCountedOpenAllocations (size_t size)
 
int DbgCountedOpenAllocations ()
 
int DbgSuppressNonFreedObjectsWarning ()
 
uinteger DbgStatAllocCounter (size_t size)
 
uinteger DbgStatAllocCounter ()
 
- Public Method Index: inherited from AllocatorMember< TAllocator >
 AllocatorMember ()=delete
 Deleted default constructor. (The allocator has to be given with construction)
 
 AllocatorMember (TAllocator &pAllocator) noexcept
 
AllocatorInterface< TAllocator > AI () const noexcept
 
TAllocator & GetAllocator () const noexcept
 
- Public Method Index: inherited from DbgCriticalSections
ALIB_FORCE_INLINE DbgCriticalSections (const char *name)
 
ALIB_FORCE_INLINE ~DbgCriticalSections ()
 Destructor. Checks that this instance is unused.
 
ALIB_API void Acquire (const CallerInfo &ci) const
 
ALIB_API void AcquireShared (const CallerInfo &ci) const
 
ALIB_API void doAssert (bool cond, const CallerInfo &ciAssert, const CallerInfo &ci, const char *headline) const
 
ALIB_API void Release (const CallerInfo &ci) const
 
ALIB_API void ReleaseShared (const CallerInfo &ci) const
 
ALIB_FORCE_INLINE void yieldOrSleep () const
 

Protected Type Index:

using allocMember = lang::AllocatorMember<TAllocator>
 A shortcut to a base type.
 

Protected Static Method Index:

template<size_t TRequestedObjectSize>
static constexpr short hookIndex ()
 
static constexpr short hookIndex (size_t requestedObjectSize)
 
static constexpr short minimumHookIndex ()
 
static constexpr short qtyHooks ()
 

Protected Field Index:

size_t dbgLastRequestedSize
 
int * dbgOpenAllocations = nullptr
 The current number of allocations that have not been freed.
 
uintegerdbgStatAllocCounter = nullptr
 The overall number of allocations for each size.
 
void ** hooks = nullptr
 
- Protected Field Index: inherited from AllocatorMember< TAllocator >
TAllocator & allocator
 A reference to the allocator.
 

Protected Method Index:

void deletePool ()
 Frees all recycled pool objects.
 

Private Static Fields Index:

static constexpr unsigned char CLEAR = 0xF3
 
static constexpr unsigned char MAGIC = 0xA3
 

Type Definition Details:

◆ allocMember

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
using allocMember = lang::AllocatorMember<TAllocator>
protected

A shortcut to a base type.

Definition at line 123 of file poolallocator.hpp.

◆ ChainedAllocator

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
using ChainedAllocator = TAllocator

The type of the allocator that this allocator uses underneath to allocate the buffers, given with template parameter TAllocator.
The instance can be accessed with inherited methods GetAllocator and AI.

Definition at line 208 of file poolallocator.hpp.

Field Details:

◆ CLEAR

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
unsigned char CLEAR = 0xF3
staticconstexprprivate

A magic byte written when memory is freed.

See also
Field CLEAR.

Definition at line 119 of file poolallocator.hpp.

◆ dbgLastRequestedSize

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
size_t dbgLastRequestedSize
protected

This member is used with ALIB_DEBUG_ALLOCATIONS to pass the requested size from interface methods to the implementation. While this approach is not thread-safe, it avoids adding some method parameter, which would exist only in debug versions. It was intentionally implemented like this, to cause testing errors in case that multithreaded access was not locked against racing conditions properly by the user.

Definition at line 156 of file poolallocator.hpp.

◆ DbgName

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
const char* DbgName

A name for this object. The constructors grab this name from the chained allocator, which most often is an already named MonoAllocator. Thus, no constructor argument is available (in contrast to class MonoAllocator). This name may be changed after construction by the using code as appropriate.

Definition at line 138 of file poolallocator.hpp.

◆ dbgOpenAllocations

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
int* dbgOpenAllocations = nullptr
protected

The current number of allocations that have not been freed.

Definition at line 149 of file poolallocator.hpp.

◆ dbgStatAllocCounter

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
uinteger* dbgStatAllocCounter = nullptr
protected

The overall number of allocations for each size.

Definition at line 144 of file poolallocator.hpp.

◆ hooks

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
void** hooks = nullptr
protected

Array of hooks. Each hook points to previously disposed memory of the same size. Its length is determined with constexpr qtyHooks and it is allocated with construction in allocator.

Definition at line 129 of file poolallocator.hpp.

◆ MAGIC

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
unsigned char MAGIC = 0xA3
staticconstexprprivate

A magic byte, used with compiler-symbol ALIB_DEBUG_ALLOCATIONS to mark memory and detect out-of-bounds writes.

See also
Method Allocator::dbgCheckMemory.

Definition at line 115 of file poolallocator.hpp.

◆ MAX_ALIGNMENT

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
size_t MAX_ALIGNMENT = TAlignment
staticconstexpr

Evaluates to the value of template parameter TAlignment.

See also
Field Allocator::MAX_ALIGNMENT.

Definition at line 216 of file poolallocator.hpp.

◆ MIN_ALIGNMENT

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
size_t MIN_ALIGNMENT = TAlignment
staticconstexpr

Evaluates to the value of template parameter TAlignment.

See also
Field Allocator::MIN_ALIGNMENT.

Definition at line 212 of file poolallocator.hpp.

Constructor(s) / Destructor Details:

◆ TPoolAllocator() [1/2]

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
ALIB_API TPoolAllocator ( TAllocator & pAllocator)

Constructs this type.

Parameters
pAllocatorThe allocator to use for allocating pool objects.

◆ TPoolAllocator() [2/2]

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
template<typename TEnableIf = allocMember, ATMP_T_IF(int, std::is_default_constructible< TEnableIf >::value) = 0>
TPoolAllocator ( )
inline

Constructs this type without a given allocator. This constructor is applicable only if TAllocator is default-constructible (e.g., HeapAllocator).

Definition at line 228 of file poolallocator.hpp.

Here is the call graph for this function:

Method Details:

◆ allocate()

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
void * allocate ( size_t & size,
size_t pAlignment )
inline

Allocates or re-uses a previously freed piece of memory of equal size. Any given size is rounded up to the next higher power of 2 before comparison and returned via in/output parameter size.

Parameters
[in,out]sizeThe size of memory the block to allocate in bytes. This will be rounded up to the next higher power of 2 when the function returns. Any additional size might be used by the caller.
pAlignmentThe (minimum) alignment of the memory block to allocate in bytes. This is ignored with this allocator. Instead, it uses what is specified by template parameter TAlignment. See Chapter 11.1 Alignment of the Programmer's Manual of this module.
Returns
Pointer to the allocated memory.

Definition at line 273 of file poolallocator.hpp.

Here is the call graph for this function:

◆ AllocateByAllocationInfo()

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
ALIB_API void * AllocateByAllocationInfo ( int allocInfo)

Allocates or recycles previously freed memory suitable to emplace an instance with the given allocation information.

Note
This method is to be used in combination with template method GetAllocInformation in situations, where the type information of the allocation is not available or has to be transferred to a non-templated library function or similar.
Parameters
allocInfoThe allocation information received with GetAllocInformation.
Returns
A pointer to the allocated memory.

◆ AllocationInformationBitCount()

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
static constexpr int AllocationInformationBitCount ( )
inlinestaticconstexpr

Returns the number of relevant bits of the allocation information value returned by overloaded methods GetAllocInformation. In other words, the value returned by these methods is between 0 and the power of 2 of the value returned by this method.

Returns
5 on 32-bit systems and 6 on 64 bit systems. GetAllocInformation.

Definition at line 350 of file poolallocator.hpp.

◆ allowsMemSplit()

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
bool allowsMemSplit ( )
constexprnoexcept

See the description of this method with prototype Allocator::allowsMemSplit.
(Note: This method is static. For technical reasons this cannot be reflected in this documentation)

Returns
false.

◆ dbgAcknowledgeIncreasedAllocSize()

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
template<typename TSize >
void dbgAcknowledgeIncreasedAllocSize ( void * mem,
TSize allocSize ) const
inline

For an explanation, see Allocator::dbgAcknowledgeIncreasedAllocSize.

Template Parameters
TSizeThe type of parameter allocSize. (Deduced by the compiler.)
Parameters
memThe address of the allocated object.
allocSizeThe true allocation size returned by the method allocate .

Definition at line 321 of file poolallocator.hpp.

Here is the call graph for this function:

◆ dbgCheckMemory()

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
template<typename TSize >
void dbgCheckMemory ( void * mem,
TSize size )
inline

If the compiler symbol ALIB_DEBUG_ALLOCATIONS is not set, this method is empty and will be optimized out. Otherwise, this will raise an ALib assertion if the piece of allocated memory is corrupted or its allocation size is not rightfully given by the using code.

See also
Chapter 11.4 Debugging of the Programmer's Manual.
Template Parameters
TSizeThe type of parameter size. (Deduced by the compiler.)
Parameters
memThe address of the allocated object.
sizeThe requested allocation size of the object.

Definition at line 477 of file poolallocator.hpp.

Here is the call graph for this function:

◆ DbgCountedOpenAllocations() [1/2]

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
int DbgCountedOpenAllocations ( )
inline

Returns the number of objects currently allocated (and not freed).
Only functional if the compiler symbol ALIB_DEBUG_ALLOCATIONS is set. Otherwise, this is a static constexpr function that returns 0.

Returns
The number of non-freed allocations.

Definition at line 498 of file poolallocator.hpp.

Here is the call graph for this function:

◆ DbgCountedOpenAllocations() [2/2]

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
int DbgCountedOpenAllocations ( size_t size)
inline

Returns the number of objects of the given size currently allocated (and not freed).
Only functional if the compiler symbol ALIB_DEBUG_ALLOCATIONS is set. Otherwise, this is a static constexpr function that returns 0.

See also
Overloaded method DbgCountedOpenAllocations() which returns the overall number.
Parameters
sizeThe size of the object requested, as given with allocate and free.
Returns
The number of non-freed allocations.

Definition at line 487 of file poolallocator.hpp.

Here is the call graph for this function:

◆ DbgStatAllocCounter() [1/2]

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
uinteger DbgStatAllocCounter ( )
inline

Returns the overall number of objects currently allocated (and not freed).
Only functional if the compiler symbol ALIB_DEBUG_MONOMEM is set. Otherwise, this is a static constexpr function that returns 0.

Returns
The number of non-freed allocations.

Definition at line 545 of file poolallocator.hpp.

Here is the call graph for this function:

◆ DbgStatAllocCounter() [2/2]

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
uinteger DbgStatAllocCounter ( size_t size)
inline

Returns the overall number of allocated (and potentially freed) objects of the given size.
Only functional if the compiler symbol ALIB_DEBUG_MONOMEM is set. Otherwise, this is a static constexpr function that returns 0.

See also
Overloaded method DbgStatAllocCounter() which returns the overall number.
Parameters
sizeThe size of the object requested, as given with allocate and free.
Returns
The number of non-freed allocations.

Definition at line 534 of file poolallocator.hpp.

Here is the call graph for this function:

◆ DbgSuppressNonFreedObjectsWarning()

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
int DbgSuppressNonFreedObjectsWarning ( )
inline

Actively suppresses a warning on destruction in case DbgCountedOpenAllocations does not return 0.
Only functional if the compiler symbol ALIB_DEBUG_ALLOCATIONS is set. Otherwise, this is a static constexpr function that returns 0.

Returns
The number of non-freed allocations.

Definition at line 513 of file poolallocator.hpp.

Here is the call graph for this function:

◆ free()

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
void free ( void * mem,
size_t size )
inline

Disposes the given memory. The fragment is stored for later reuse with method allocate of memory sizes of the same power of 2 range.

Parameters
memThe memory to dispose.
sizeThe size of the given mem.

Definition at line 308 of file poolallocator.hpp.

Here is the call graph for this function:

◆ FreeByAllocationInfo()

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
void FreeByAllocationInfo ( int allocInfo,
void * mem )
inline

Disposes an object (or piece of memory) which has been allocated using AllocateByAllocationInfo. If compiler symbol ALIB_DEBUG_ALLOCATIONS is set, the method will overwrite the freed memory with character 0xD3.

Parameters
allocInfoThe allocation information received with GetAllocInformation.
memThe object to dispose.

Definition at line 427 of file poolallocator.hpp.

Here is the call graph for this function:

◆ GetAllocationSize()

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
static constexpr size_t GetAllocationSize ( short allocInfo)
inlinestaticconstexpr

Returns the allocation size for a value returned by GetAllocInformation.

Parameters
allocInfoThe alloc information received with GetAllocInformation.
Returns
The next higher power of 2 in respect to the size passed as parameter to GetAllocInformation.

Definition at line 405 of file poolallocator.hpp.

Here is the call graph for this function:

◆ GetAllocInformation() [1/2]

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
template<typename T >
static constexpr short GetAllocInformation ( )
inlinestaticconstexpr

This static constexpr method returns information that this allocator needs for allocation and freeing of objects. In the case that the original allocation type is not known on deletion (e.g., if virtual destructors are used), then this piece of information has to be collected with this function (probably on construction) and provided to FreeByAllocationInfo via custom mechanics.

Note
Two options are quite obvious to implement:
  1. The information is stored within the object and passed on destruction.
  2. The information is retrieved from a virtual function, which is implemented using this constexpr type.
While the second version has a small impact on code size and execution speed (because the virtual function has to be called with deletion), the first version increases the footprint of the object. So both approaches have their advantages and disadvantages.

A third option is explained in a step-by-step sample in chapter 6.3 Using Meta-Info Singletons to Reclaim Allocation Information of the Programmer's Manual of this module.

Technically, the returned value is the exponent base 2 of the next higher power of 2 value, minus the minimum supported exponent. This directly gives an index into field hooks.

Template Parameters
TThe object type that allocation information is to be retrieved for.
Returns
Allocation information.

Definition at line 379 of file poolallocator.hpp.

Here is the call graph for this function:

◆ GetAllocInformation() [2/2]

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
template<typename TIntegral >
static constexpr short GetAllocInformation ( TIntegral size)
staticconstexpr

Same as templated GetAllocInformation<T>() version, but accepts method parameter size instead of a template parameter. Thus, only potentially constexpr.

Template Parameters
TIntegralThe type that parameter size is provided with. If not integral, this method is not chosen by the compiler.
Parameters
sizeThe size of the object to be allocated or disposed in a probalble next step.
Returns
Allocation information. See GetAllocInformation<T>().

◆ GetPoolSize()

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
ALIB_API integer GetPoolSize ( size_t size)

Returns the number of available pool objects, hence those that had been allocated, freed, and not been reused with a next allocation again.

Parameters
sizeThe size of the object requested, as given with allocate and free.
Returns
The number of pool objects of the given size.

◆ hookIndex() [1/2]

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
template<size_t TRequestedObjectSize>
static constexpr short hookIndex ( )
inlinestaticconstexprprotected

Templated version of hookIndex(size_t).

Template Parameters
TRequestedObjectSizeThe object size requested by the user, hence excluding the internal pointer.
Returns
The index of the recycler hook in hooks.

Definition at line 191 of file poolallocator.hpp.

Here is the call graph for this function:

◆ hookIndex() [2/2]

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
static constexpr short hookIndex ( size_t requestedObjectSize)
inlinestaticconstexprprotected

Calculates the index of the hook in field hooks. This corresponds to the number of the most significant bit in the next higher power of 2 value minus minimumHookIndex.

Parameters
requestedObjectSizeThe object size requested by the user.
Returns
The index of the recycler hook in hooks.

Definition at line 176 of file poolallocator.hpp.

Here is the call graph for this function:

◆ minimumHookIndex()

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
static constexpr short minimumHookIndex ( )
inlinestaticconstexprprotected

To be able to store allocated memory in the recycling stacks, any allocated memory is at least of size sizeof(void*). Hence sizes 1 and 2 (with 64-bit systems also 4) will never be allocated and no hook is available for these sizes.

Returns
3 on 64-bit systems, 2 on 32-bit systems.

Definition at line 164 of file poolallocator.hpp.

◆ operator()()

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
lang::AllocatorInterface< TPoolAllocator > operator() ( )
inline

Returns a temporary object (which is usually optimized out together with a call to this operator) providing high-level convenience methods for allocation.

See also
Class lang::AllocatorInterface
Returns
A temporary high-level interface into the allocator.

Definition at line 338 of file poolallocator.hpp.

◆ qtyHooks()

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
static constexpr short qtyHooks ( )
inlinestaticconstexprprotected

The number of hooks needed. Evaluates to 61 on a common 64-bit platform and 29 on a

Returns
61 on 64-bit systems, 29 on 32-bit systems.

Definition at line 169 of file poolallocator.hpp.

Here is the call graph for this function:

◆ reallocate()

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
void * reallocate ( void * mem,
size_t oldSize,
size_t & newSize,
size_t pAlignment )

Shrinks or grows a piece of memory. If a new allocation was performed the existing data is copied. Any given oldSize and newSize is rounded up to the next higher power of 2 before comparison. Note, that parameter newSize is provided as a reference.

Parameters
memThe memory to reallocate.
oldSizeThe current size of mem.
[in,out]newSizeThe size of memory the block to allocate in bytes. This will be rounded up to the next higher power of 2 when the function returns. Any additional size might be used by the caller.
pAlignmentThe (minimum) alignment of the memory to allocate in bytes. This is ignored with this allocator. Instead, it uses what is specified by template parameter TAlignment. See Chapter 11.1 Alignment of the Programmer's Manual of this module.
Returns
Pointer to the re-allocated memory.

◆ Reset()

template<typename TAllocator , size_t TAlignment = ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
void Reset ( )
inline

Deletes all current pool objects with the ChainedAllocator. The state of this class equals the state after construction.

Definition at line 448 of file poolallocator.hpp.

Here is the call graph for this function:

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