UMPIRE
Umpire: resource management and provision
umpire::strategy::FixedPool Class Reference

Pool for fixed size allocations. More...

#include </home/docs/checkouts/readthedocs.org/user_builds/umpire/checkouts/develop/src/umpire/strategy/FixedPool.hpp>

Inheritance diagram for umpire::strategy::FixedPool:

Public Member Functions

 FixedPool (const std::string &name, int id, Allocator allocator, const std::size_t object_bytes, const std::size_t objects_per_pool=64 *sizeof(int) *8) noexcept
 Constructs a FixedPool. More...
 
 ~FixedPool ()
 
 FixedPool (const FixedPool &)=delete
 
void * allocate (std::size_t bytes=0) override final
 Allocate bytes of memory. More...
 
void deallocate (void *ptr, std::size_t size) override final
 Free the memory at ptr. More...
 
void release () override final
 Release any and all unused memory held by this AllocationStrategy. More...
 
std::size_t getCurrentSize () const noexcept override final
 Get current (total) size of the allocated memory. More...
 
std::size_t getHighWatermark () const noexcept override final
 Get the high watermark of the total allocated size. More...
 
std::size_t getActualSize () const noexcept override final
 Get the current amount of memory allocated by this allocator. More...
 
Platform getPlatform () noexcept override final
 Get the platform associated with this AllocationStrategy. More...
 
MemoryResourceTraits getTraits () const noexcept override final
 
bool pointerIsFromPool (void *ptr) const noexcept
 
std::size_t numPools () const noexcept
 
void * allocate_internal (std::size_t bytes)
 
void * allocate_named_internal (const std::string &name, std::size_t bytes)
 
void deallocate_internal (void *ptr, std::size_t size=0)
 
virtual std::size_t getAllocationCount () const noexcept
 Get the total number of active allocations by this allocator. More...
 
const std::string & getName () noexcept
 Get the name of this AllocationStrategy. More...
 
const std::string & getStrategyName () const noexcept
 
int getId () noexcept
 Get the id of this AllocationStrategy. More...
 
virtual AllocationStrategygetParent () const noexcept
 Traces where the allocator came from. More...
 
virtual bool tracksMemoryUse () const noexcept
 
bool isTracked () const noexcept
 

Public Attributes

std::size_t m_current_size {0}
 
std::size_t m_high_watermark {0}
 
std::size_t m_allocation_count {0}
 

Protected Member Functions

void setTracking (bool) noexcept
 

Protected Attributes

std::string m_name
 
std::string m_strategy_name
 
int m_id
 
bool m_tracked {true}
 
AllocationStrategym_parent
 

Detailed Description

Pool for fixed size allocations.

This AllocationStrategy provides an efficient pool for fixed size allocations, and used to quickly allocate and deallocate objects.

Constructor & Destructor Documentation

◆ FixedPool() [1/2]

umpire::strategy::FixedPool::FixedPool ( const std::string &  name,
int  id,
Allocator  allocator,
const std::size_t  object_bytes,
const std::size_t  objects_per_pool = 64 * sizeof(int) * 8 
)
noexcept

Constructs a FixedPool.

Parameters
nameThe allocator name for reference later in ResourceManager
idThe allocator id for reference later in ResourceManager
allocatorUsed for data allocation. It uses std::malloc for internal tracking of these allocations.
object_bytesThe fixed size (in bytes) for each allocation
objects_per_poolNumber of objects in each sub-pool internally. Performance likely improves if this is large, at the cost of memory usage. This does not have to be a multiple of sizeof(int)*8, but it will also likely improve performance if so.

◆ ~FixedPool()

umpire::strategy::FixedPool::~FixedPool ( )

◆ FixedPool() [2/2]

umpire::strategy::FixedPool::FixedPool ( const FixedPool )
delete

Member Function Documentation

◆ allocate()

void * umpire::strategy::FixedPool::allocate ( std::size_t  bytes = 0)
finaloverridevirtual

Allocate bytes of memory.

Parameters
bytesNumber of bytes to allocate.
Returns
Pointer to start of allocated bytes.

Implements umpire::strategy::AllocationStrategy.

References UMPIRE_ASSERT, and UMPIRE_ERROR.

Referenced by umpire::strategy::mixins::AllocateNull::allocateNull().

◆ deallocate()

void umpire::strategy::FixedPool::deallocate ( void *  ptr,
std::size_t  size 
)
finaloverridevirtual

Free the memory at ptr.

Parameters
ptrPointer to free.

Implements umpire::strategy::AllocationStrategy.

References umpire::strategy::bits_per_int, UMPIRE_ASSERT, and UMPIRE_ERROR.

Referenced by umpire::strategy::mixins::AllocateNull::deallocateNull().

◆ release()

void umpire::strategy::FixedPool::release ( )
finaloverridevirtual

Release any and all unused memory held by this AllocationStrategy.

Reimplemented from umpire::strategy::AllocationStrategy.

References umpire::free().

◆ getCurrentSize()

std::size_t umpire::strategy::FixedPool::getCurrentSize ( ) const
finaloverridevirtualnoexcept

Get current (total) size of the allocated memory.

This is the total size of all allocation currently 'live' that have been made by this AllocationStrategy object.

Returns
Current total size of allocations.

Reimplemented from umpire::strategy::AllocationStrategy.

◆ getHighWatermark()

std::size_t umpire::strategy::FixedPool::getHighWatermark ( ) const
finaloverridevirtualnoexcept

Get the high watermark of the total allocated size.

This is equivalent to the highest observed value of getCurrentSize.

Returns
High watermark allocation size.

Reimplemented from umpire::strategy::AllocationStrategy.

◆ getActualSize()

std::size_t umpire::strategy::FixedPool::getActualSize ( ) const
finaloverridevirtualnoexcept

Get the current amount of memory allocated by this allocator.

Note that this can be larger than getCurrentSize(), particularly if the AllocationStrategy implements some kind of pooling.

Returns
The total size of all the memory this object has allocated.

Reimplemented from umpire::strategy::AllocationStrategy.

◆ getPlatform()

Platform umpire::strategy::FixedPool::getPlatform ( )
finaloverridevirtualnoexcept

Get the platform associated with this AllocationStrategy.

The Platform distinguishes the appropriate place to execute operations on memory allocated by this AllocationStrategy.

Returns
The platform associated with this AllocationStrategy.

Implements umpire::strategy::AllocationStrategy.

◆ getTraits()

MemoryResourceTraits umpire::strategy::FixedPool::getTraits ( ) const
finaloverridevirtualnoexcept

◆ pointerIsFromPool()

bool umpire::strategy::FixedPool::pointerIsFromPool ( void *  ptr) const
noexcept

◆ numPools()

std::size_t umpire::strategy::FixedPool::numPools ( ) const
noexcept

◆ allocate_internal()

◆ allocate_named_internal()

void * umpire::strategy::AllocationStrategy::allocate_named_internal ( const std::string &  name,
std::size_t  bytes 
)
inherited

◆ deallocate_internal()

◆ getAllocationCount()

std::size_t umpire::strategy::AllocationStrategy::getAllocationCount ( ) const
virtualnoexceptinherited

Get the total number of active allocations by this allocator.

Returns
The total number of active allocations this object has allocated.

References umpire::strategy::AllocationStrategy::m_allocation_count.

Referenced by umpire::Allocator::getAllocationCount().

◆ getName()

◆ getStrategyName()

const std::string & umpire::strategy::AllocationStrategy::getStrategyName ( ) const
noexceptinherited

◆ getId()

int umpire::strategy::AllocationStrategy::getId ( )
noexceptinherited

◆ getParent()

AllocationStrategy * umpire::strategy::AllocationStrategy::getParent ( ) const
virtualnoexceptinherited

Traces where the allocator came from.

Returns
Pointer to the parent AllocationStrategy.

References umpire::strategy::AllocationStrategy::m_parent.

Referenced by umpire::ResourceManager::destroyAllocator(), umpire::Allocator::getParent(), and umpire::is_accessible().

◆ tracksMemoryUse()

bool umpire::strategy::AllocationStrategy::tracksMemoryUse ( ) const
virtualnoexceptinherited

◆ isTracked()

bool umpire::strategy::AllocationStrategy::isTracked ( ) const
noexceptinherited

◆ setTracking()

void umpire::strategy::AllocationStrategy::setTracking ( bool  tracking)
protectednoexceptinherited

Member Data Documentation

◆ m_current_size

◆ m_high_watermark

◆ m_allocation_count

◆ m_name

std::string umpire::strategy::AllocationStrategy::m_name
protectedinherited

◆ m_strategy_name

std::string umpire::strategy::AllocationStrategy::m_strategy_name
protectedinherited

◆ m_id

int umpire::strategy::AllocationStrategy::m_id
protectedinherited

◆ m_tracked

bool umpire::strategy::AllocationStrategy::m_tracked {true}
protectedinherited

◆ m_parent

AllocationStrategy* umpire::strategy::AllocationStrategy::m_parent
protectedinherited