33#ifndef DART_COMMON_POOLALLOCATOR_HPP_
34#define DART_COMMON_POOLALLOCATOR_HPP_
73 [[nodiscard]]
void*
allocate(
size_t bytes)
noexcept override;
76 void deallocate(
void* pointer,
size_t bytes)
override;
79 void print(std::ostream& os = std::cout,
int indent = 0)
const override;
#define DART_STRING_TYPE(type_name)
Definition Castable.hpp:38
Base class for std::allocator compatible allocators.
Definition MemoryAllocator.hpp:46
static MemoryAllocator & GetDefault()
Returns the default memory allocator.
Definition MemoryAllocator.cpp:41
Memory allocator optimized for allocating many objects of the same or similar sizes.
Definition PoolAllocator.hpp:47
std::mutex mMutex
Mutex for for mNumAllocatedMemoryBlocks, mNumMemoryBlocks, mFreeMemoryUnits, and mAllocatedMemoryBloc...
Definition PoolAllocator.hpp:111
MemoryBlock * mMemoryBlocks
The array of memory blocks.
Definition PoolAllocator.hpp:117
MemoryAllocator & mBaseAllocator
The base allocator to allocate memory chunk.
Definition PoolAllocator.hpp:107
void deallocate(void *pointer, size_t bytes) override
Deallocates the storage referenced by the pointer p, which must be a pointer obtained by an earlier c...
Definition PoolAllocator.cpp:193
int mMemoryBlocksSize
The size of mMemoryBlocks.
Definition PoolAllocator.hpp:123
int getNumAllocatedMemoryBlocks() const
Returns the count of allocated memory blocks.
Definition PoolAllocator.cpp:114
static std::array< size_t, HEAP_COUNT > mUnitSizes
Definition PoolAllocator.hpp:100
~PoolAllocator() override
Destructor.
Definition PoolAllocator.cpp:88
void * allocate(size_t bytes) noexcept override
Allocates size bytes of uninitialized storage.
Definition PoolAllocator.cpp:120
const MemoryAllocator & getBaseAllocator() const
Returns the base allocator.
Definition PoolAllocator.cpp:102
int mCurrentMemoryBlockIndex
The count of the allocated memory blocks in use.
Definition PoolAllocator.hpp:126
static constexpr int HEAP_COUNT
Definition PoolAllocator.hpp:94
static bool mInitialized
Definition PoolAllocator.hpp:104
static constexpr size_t MAX_UNIT_SIZE
Definition PoolAllocator.hpp:96
void print(std::ostream &os=std::cout, int indent=0) const override
Prints state of the memory allocator.
Definition PoolAllocator.cpp:217
std::array< MemoryUnit *, HEAP_COUNT > mFreeMemoryUnits
List of free memory units.
Definition PoolAllocator.hpp:136
static constexpr size_t BLOCK_SIZE
Definition PoolAllocator.hpp:98
static std::array< int, MAX_UNIT_SIZE+1 > mMapSizeToHeapIndex
Definition PoolAllocator.hpp:102
Definition PoolAllocator.hpp:89
MemoryUnit * mMemoryUnits
Pointer to the first memory unit.
Definition PoolAllocator.hpp:91
Definition PoolAllocator.hpp:83
MemoryUnit * mNext
Pointer to next memory block.
Definition PoolAllocator.hpp:85