8#ifndef HPP_ALIB_MONOMEM_POOLALLOCATOR
9#define HPP_ALIB_MONOMEM_POOLALLOCATOR 1
13#include "alib/monomem/monoallocator.hpp"
19#if !defined(ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT)
20# define ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT alignof(uint64_t)
92template<
typename TAllocator,
size_t TAlignment= ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>
94#if ALIB_DEBUG_CRITICAL_SECTIONS
98 static_assert( TAlignment >=
alignof(
void*),
99 "The (fixed) alignment of the pool allocator has to be at least as high as alignof(void*). "
100 "Adjust template parameter TAlignment." );
102 static_assert( TAlignment <= TAllocator::MAX_ALIGNMENT,
103 "The (fixed) alignment of the pool allocator cannot be greater than the MAX_ALIGNMENT of "
104 "its chained allocator. Adjust template parameter TAlignment." );
106 #if ALIB_CPP_STANDARD >= 20 || !defined(_WIN32)
108 "The fixed alignment of the pool allocator is not a power of 2. "
109 "Adjust template parameter TAlignment." );
115 static constexpr unsigned char MAGIC= 0xA3;
119 static constexpr unsigned char CLEAR= 0xF3;
142 #if ALIB_DEBUG_MONOMEM
147 #if ALIB_DEBUG_ALLOCATIONS
178 if( requestedObjectSize <
sizeof(
void*) )
189 template<
size_t TRequestedObjectSize>
193 if( TRequestedObjectSize <
sizeof(
void*) )
195 constexpr int msb =
lang::MSB(TRequestedObjectSize);
227 ATMP_T_IF(
int, std::is_default_constructible<TEnableIf>::value )= 0>
229 #if ALIB_DEBUG_CRITICAL_SECTIONS
233 #if ALIB_CPP_STANDARD < 20 && defined(_WIN32)
235 "The fixed alignment of the pool allocator is not a power of 2. "
236 "Adjust template parameter TAlignment." )
244 #if ALIB_DEBUG_ALLOCATIONS
248 #if ALIB_DEBUG_MONOMEM
276 "The requested alignment is higher than what was specified with "
277 "template parameter TAlignment." )
280 #if ALIB_DEBUG_ALLOCATIONS
301 void*
reallocate(
void* mem,
size_t oldSize,
size_t& newSize,
size_t pAlignment );
308 void free(
void* mem,
size_t size)
310 #if ALIB_DEBUG_ALLOCATIONS
320 template<
typename TSize>
389 template<
typename TIntegral>
393 template<
typename TIntegral>
430 #if ALIB_DEBUG_ALLOCATIONS
441 *
reinterpret_cast<void**
>(mem)=
hooks[allocInfo];
442 hooks[allocInfo]= mem;
452 #if ALIB_DEBUG_ALLOCATIONS
455 #if ALIB_DEBUG_MONOMEM
476 template<
typename TSize>
480 #if ALIB_DEBUG_ALLOCATIONS
526 #if ALIB_DEBUG_MONOMEM
563extern template ALIB_API class TPoolAllocator< MonoAllocator, ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>;
564extern template ALIB_API class TPoolAllocator<lang::HeapAllocator, ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT>;
static constexpr short qtyHooks()
lang::AllocatorInterface< TPoolAllocator > operator()()
uinteger * dbgStatAllocCounter
The overall number of allocations for each size.
void * allocate(size_t &size, size_t pAlignment)
static constexpr unsigned char MAGIC
static constexpr short hookIndex()
static constexpr short GetAllocInformation()
static constexpr size_t GetAllocationSize(short allocInfo)
static constexpr short GetAllocInformation(TIntegral size)
void dbgAcknowledgeIncreasedAllocSize(void *mem, TSize allocSize) const
static constexpr short minimumHookIndex()
static constexpr size_t MIN_ALIGNMENT
TAllocator ChainedAllocator
void FreeByAllocationInfo(int allocInfo, void *mem)
void deletePool()
Frees all recycled pool objects.
ALIB_API integer GetPoolSize(size_t size)
int DbgSuppressNonFreedObjectsWarning()
ALIB_API ~TPoolAllocator()
Destructs this type.
uinteger DbgStatAllocCounter()
static constexpr int AllocationInformationBitCount()
ALIB_API TPoolAllocator(TAllocator &pAllocator)
int * dbgOpenAllocations
The current number of allocations that have not been freed.
void * reallocate(void *mem, size_t oldSize, size_t &newSize, size_t pAlignment)
void free(void *mem, size_t size)
static constexpr unsigned char CLEAR
static constexpr short hookIndex(size_t requestedObjectSize)
int DbgCountedOpenAllocations()
size_t dbgLastRequestedSize
int DbgCountedOpenAllocations(size_t size)
lang::AllocatorMember< TAllocator > allocMember
A shortcut to a base type.
static constexpr size_t MAX_ALIGNMENT
ALIB_API void * AllocateByAllocationInfo(int allocInfo)
uinteger DbgStatAllocCounter(size_t size)
constexpr bool allowsMemSplit() noexcept
void dbgCheckMemory(void *mem, TSize size)
#define ALIB_ASSERT_MODULE(modulename)
#define ALIB_WARNINGS_RESTORE
#define ALIB_ASSERT_ERROR(cond,...)
#define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE
#define ALIB_REL_DBG(releaseCode,...)
#define ATMP_T_IF(T, Cond)
constexpr int BitCount(TIntegral value)
constexpr TIntegral LowerMask()
constexpr int MSB(TIntegral value)
lang::uinteger uinteger
Type alias in namespace alib.
monomem::TPoolAllocator< MonoAllocator, ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT > PoolAllocator
monomem::TPoolAllocator< lang::HeapAllocator, ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT > PoolAllocatorHA
lang::integer integer
Type alias in namespace alib.
AllocatorInterface< TAllocator > AI() const noexcept
TAllocator & GetAllocator() const noexcept
static void checkMem(void *mem, const TSize size, unsigned char magic, const char *name)
static constexpr void clearMem(T *mem, size_t size, unsigned char magic)
static constexpr void annotate(T *mem, size_t size, unsigned char magic)