DART 6.13.2
|
Memory allocator optimized for allocating many objects of the same or similar sizes. More...
#include <PoolAllocator.hpp>
Classes | |
struct | MemoryBlock |
struct | MemoryUnit |
Public Types | |
using | Debug = MemoryAllocatorDebugger< PoolAllocator > |
Public Member Functions | |
PoolAllocator (MemoryAllocator &baseAllocator=MemoryAllocator::GetDefault()) | |
Constructor. | |
~PoolAllocator () override | |
Destructor. | |
const std::string & | getType () const override |
Returns type string. | |
void | _ANONYMOUS_FUNCTION_1 () |
const MemoryAllocator & | getBaseAllocator () const |
Returns the base allocator. | |
MemoryAllocator & | getBaseAllocator () |
Returns the base allocator. | |
int | getNumAllocatedMemoryBlocks () const |
Returns the count of allocated memory blocks. | |
void * | allocate (size_t bytes) noexcept override |
Allocates size bytes of uninitialized storage. | |
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 cal to allocate(). | |
void | print (std::ostream &os=std::cout, int indent=0) const override |
Prints state of the memory allocator. | |
template<typename T > | |
T * | allocateAs (size_t n=1) noexcept |
Allocates object(s) without calling the constructor. | |
template<typename T , typename... Args> | |
T * | construct (Args &&... args) noexcept |
Allocates uninitialized storage and constructs an object of type T to the allocated storage. | |
template<typename T , typename... Args> | |
T * | constructAt (void *pointer, Args &&... args) |
template<typename T , typename... Args> | |
T * | constructAt (T *pointer, Args &&... args) |
template<typename T > | |
void | destroy (T *object) noexcept |
Calls the destructor of the object and deallocate the storage. | |
bool | is () const |
Returns true if the types of this Base and the template parameter (a base class) are identical. | |
const Derived * | as () const |
Casts to pointer of Derived if Base is its base class. | |
Derived * | as () |
Casts to pointer of Derived if Base is its base class. | |
const Derived & | asRef () const |
Casts to reference of Derived if Base is its base class. UB otherwise. | |
Derived & | asRef () |
Casts to reference of Derived if Base is its base class. UB otherwise. | |
Static Public Member Functions | |
static const std::string & | getStaticType () |
Returns type string. | |
static MemoryAllocator & | GetDefault () |
Returns the default memory allocator. | |
Private Member Functions | |
const MemoryAllocator & | base () const |
Casts to Base const-reference. | |
MemoryAllocator & | base () |
Casts to Base reference. | |
Private Attributes | |
MemoryAllocator & | mBaseAllocator |
The base allocator to allocate memory chunk. | |
std::mutex | mMutex |
Mutex for for mNumAllocatedMemoryBlocks, mNumMemoryBlocks, mFreeMemoryUnits, and mAllocatedMemoryBlocks. | |
MemoryBlock * | mMemoryBlocks |
The array of memory blocks. | |
int | mMemoryBlocksSize |
The size of mMemoryBlocks. | |
int | mCurrentMemoryBlockIndex |
The count of the allocated memory blocks in use. | |
std::array< MemoryUnit *, HEAP_COUNT > | mFreeMemoryUnits |
List of free memory units. | |
Static Private Attributes | |
static constexpr int | HEAP_COUNT = 128 |
static constexpr size_t | MAX_UNIT_SIZE = 1024 |
static constexpr size_t | BLOCK_SIZE = 16 * MAX_UNIT_SIZE |
static std::array< size_t, HEAP_COUNT > | mUnitSizes |
static std::array< int, MAX_UNIT_SIZE+1 > | mMapSizeToHeapIndex |
static bool | mInitialized = false |
Memory allocator optimized for allocating many objects of the same or similar sizes.
|
explicit |
Constructor.
[in] | baseAllocator | (optional) Base memory allocator. |
[in] | initialAllocation | (optional) Bytes to initially allocate. |
|
override |
Destructor.
void dart::common::PoolAllocator::_ANONYMOUS_FUNCTION_1 | ( | ) |
|
overridevirtualnoexcept |
Allocates size
bytes of uninitialized storage.
[in] | bytes | The byte size to allocate sotrage for. |
Implements dart::common::MemoryAllocator.
|
noexceptinherited |
Allocates object(s) without calling the constructor.
This is identical to static_cast<T*>
(allocate(n * sizeof(T))).
[in] | n | The number of objects to allocate. |
|
inherited |
Casts to pointer of Derived if Base is its base class.
Returns nullptr otherwise.
|
inherited |
Casts to pointer of Derived if Base is its base class.
Returns nullptr otherwise.
|
inherited |
Casts to reference of Derived if Base is its base class. UB otherwise.
|
inherited |
Casts to reference of Derived if Base is its base class. UB otherwise.
|
privateinherited |
Casts to Base reference.
|
privateinherited |
Casts to Base const-reference.
|
noexceptinherited |
Allocates uninitialized storage and constructs an object of type T to the allocated storage.
T | The object type to construct. |
Args... | The argument types to pass to the object constructor. |
[in] | args | The constructor arguments to use. |
|
inherited |
|
inherited |
|
overridevirtual |
Deallocates the storage referenced by the pointer p
, which must be a pointer obtained by an earlier cal to allocate().
[in] | pointer | Pointer obtained from allocate(). |
[in] | bytes | The bytes of the allocated memory. |
Implements dart::common::MemoryAllocator.
|
noexceptinherited |
Calls the destructor of the object and deallocate the storage.
MemoryAllocator & dart::common::PoolAllocator::getBaseAllocator | ( | ) |
Returns the base allocator.
const MemoryAllocator & dart::common::PoolAllocator::getBaseAllocator | ( | ) | const |
Returns the base allocator.
|
staticinherited |
Returns the default memory allocator.
int dart::common::PoolAllocator::getNumAllocatedMemoryBlocks | ( | ) | const |
Returns the count of allocated memory blocks.
|
inlinestatic |
Returns type string.
|
inlineoverridevirtual |
Returns type string.
Implements dart::common::MemoryAllocator.
|
inherited |
Returns true if the types of this Base
and the template parameter (a base class) are identical.
This function is a syntactic sugar, which is identical to: (getType() == ShapeType::getStaticType()).
Example code:
|
overridevirtual |
Prints state of the memory allocator.
Reimplemented from dart::common::MemoryAllocator.
|
inlinestaticconstexprprivate |
|
inlinestaticconstexprprivate |
|
inlinestaticconstexprprivate |
|
private |
The base allocator to allocate memory chunk.
|
private |
The count of the allocated memory blocks in use.
|
private |
List of free memory units.
The size of mFreeMemoryUnits is fixed to HEAP_COUNT where each element is for a specific memory size. For example, the first element has the free memory unit for 8 bytes while the last element has the free memory unit for 1024 bytes.
The size must be the same of mUnitSizes.
|
inlinestaticprivate |
|
inlinestaticprivate |
|
private |
The array of memory blocks.
This array is a placeholder of allocated memory blocks. Initially this contains nullptr as the elements.
|
private |
The size of mMemoryBlocks.
This is simply the current size of mMemoryBlocks. The value doesn't mean the actual count of the allocated memory blocks.
|
mutableprivate |
Mutex for for mNumAllocatedMemoryBlocks, mNumMemoryBlocks, mFreeMemoryUnits, and mAllocatedMemoryBlocks.
|
inlinestaticprivate |