BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlma::ConcurrentMultipoolAllocator Class Reference

#include <bdlma_concurrentmultipoolallocator.h>

Inheritance diagram for bdlma::ConcurrentMultipoolAllocator:
bdlma::ManagedAllocator bslma::Allocator bsl::memory_resource

Public Member Functions

 ConcurrentMultipoolAllocator (bslma::Allocator *basicAllocator=0)
 
 ConcurrentMultipoolAllocator (int numPools, bslma::Allocator *basicAllocator=0)
 
 ConcurrentMultipoolAllocator (bsls::BlockGrowth::Strategy growthStrategy, bslma::Allocator *basicAllocator=0)
 
 ConcurrentMultipoolAllocator (int numPools, bsls::BlockGrowth::Strategy growthStrategy, bslma::Allocator *basicAllocator=0)
 
 ConcurrentMultipoolAllocator (int numPools, bsls::BlockGrowth::Strategy growthStrategy, int maxBlocksPerChunk, bslma::Allocator *basicAllocator=0)
 
 ConcurrentMultipoolAllocator (int numPools, const bsls::BlockGrowth::Strategy *growthStrategyArray, bslma::Allocator *basicAllocator=0)
 
 ConcurrentMultipoolAllocator (int numPools, const bsls::BlockGrowth::Strategy *growthStrategyArray, int maxBlocksPerChunk, bslma::Allocator *basicAllocator=0)
 
 ConcurrentMultipoolAllocator (int numPools, bsls::BlockGrowth::Strategy growthStrategy, const int *maxBlocksPerChunkArray, bslma::Allocator *basicAllocator=0)
 
 ConcurrentMultipoolAllocator (int numPools, const bsls::BlockGrowth::Strategy *growthStrategyArray, const int *maxBlocksPerChunkArray, bslma::Allocator *basicAllocator=0)
 
 ~ConcurrentMultipoolAllocator () BSLS_KEYWORD_OVERRIDE
 
void reserveCapacity (bsls::Types::size_type size, int numObjects)
 
void * allocate (bsls::Types::size_type size) BSLS_KEYWORD_OVERRIDE
 
void deallocate (void *address) BSLS_KEYWORD_OVERRIDE
 
void release () BSLS_KEYWORD_OVERRIDE
 
int numPools () const
 Return the number of pools managed by this multipool allocator.
 
bsls::Types::size_type maxPooledBlockSize () const
 
- Public Member Functions inherited from bslma::Allocator
 ~Allocator () BSLS_KEYWORD_OVERRIDE
 
template<class TYPE >
void deleteObject (const TYPE *object)
 
template<class TYPE >
void deleteObjectRaw (const TYPE *object)
 
void deleteObject (bsl::nullptr_t)
 
void deleteObjectRaw (bsl::nullptr_t)
 
- Public Member Functions inherited from bsl::memory_resource
 memory_resource () BSLS_KEYWORD_DEFAULT
 Create this object. Has no effect other than to begin its lifetime.
 
 memory_resource (const memory_resource &) BSLS_KEYWORD_DEFAULT
 
virtual ~memory_resource ()
 Destroy this object. Has no effect other than to end its lifetime.
 
memory_resourceoperator= (const memory_resource &) BSLS_KEYWORD_DEFAULT
 Return a modifiable reference to this object.
 
BSLS_ANNOTATION_NODISCARD void * allocate (size_t bytes, size_t alignment=k_MAX_ALIGN)
 
void deallocate (void *p, size_t bytes, size_t alignment=k_MAX_ALIGN)
 
bool is_equal (const memory_resource &other) const BSLS_KEYWORD_NOEXCEPT
 

Additional Inherited Members

- Public Types inherited from bslma::Allocator
typedef std::size_t size_type
 
- Static Public Member Functions inherited from bslma::Allocator
static void throwBadAlloc ()
 
- Protected Member Functions inherited from bslma::Allocator
void * do_allocate (std::size_t bytes, std::size_t alignment) BSLS_KEYWORD_OVERRIDE
 
void do_deallocate (void *p, std::size_t bytes, std::size_t alignment) BSLS_KEYWORD_OVERRIDE
 
bool do_is_equal (const memory_resource &other) const BSLS_KEYWORD_NOEXCEPT BSLS_KEYWORD_OVERRIDE
 

Detailed Description

This class implements the bdlma::ManagedAllocator protocol to provide a thread-safe allocator that maintains a configurable number of Pool objects, each dispensing memory blocks of a unique size. The Pool objects are placed in an array, with each successive pool managing memory blocks of size twice that of the previous pool. Each multipool allocation (deallocation) request allocates memory from (returns memory to) the internal pool having the smallest block size not less than the requested size, or, if no pool manages memory blocks of sufficient sized, from a separately managed list of memory blocks. Both the release method and the destructor of a ConcurrentMultipoolAllocator release all memory currently allocated via the object.

See bdlma_concurrentmultipoolallocator

Constructor & Destructor Documentation

◆ ConcurrentMultipoolAllocator() [1/9]

bdlma::ConcurrentMultipoolAllocator::ConcurrentMultipoolAllocator ( bslma::Allocator basicAllocator = 0)
inlineexplicit

◆ ConcurrentMultipoolAllocator() [2/9]

bdlma::ConcurrentMultipoolAllocator::ConcurrentMultipoolAllocator ( int  numPools,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

◆ ConcurrentMultipoolAllocator() [3/9]

bdlma::ConcurrentMultipoolAllocator::ConcurrentMultipoolAllocator ( bsls::BlockGrowth::Strategy  growthStrategy,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

◆ ConcurrentMultipoolAllocator() [4/9]

bdlma::ConcurrentMultipoolAllocator::ConcurrentMultipoolAllocator ( int  numPools,
bsls::BlockGrowth::Strategy  growthStrategy,
bslma::Allocator basicAllocator = 0 
)
inline

◆ ConcurrentMultipoolAllocator() [5/9]

bdlma::ConcurrentMultipoolAllocator::ConcurrentMultipoolAllocator ( int  numPools,
bsls::BlockGrowth::Strategy  growthStrategy,
int  maxBlocksPerChunk,
bslma::Allocator basicAllocator = 0 
)
inline

Create a multipool allocator. Optionally specify numPools, indicating the number of internally created Pool objects; the block size of the first pool is 8 bytes, with the block size of each additional pool successively doubling. If numPools is not specified, an implementation-defined number of pools N – covering memory blocks ranging in size from 2^3 = 8 to 2^(N+2) – are created. Optionally specify a growthStrategy indicating whether the number of blocks allocated at once for every internally created Pool should be either fixed or grow geometrically, starting with

  1. If growthStrategy is not specified, the allocation strategy for each internally created Pool object is geometric, starting from 1. If numPools is specified, optionally specify a maxBlocksPerChunk, indicating the maximum number of blocks to be allocated at once when a pool must be replenished. If maxBlocksPerChunk is not specified, an implementation-defined value is used. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used. Memory allocation (and deallocation) requests will be satisfied using the internally maintained pool managing memory blocks of the smallest size not less than the requested size, or directly from the underlying allocator (supplied at construction), if no internally pool managing memory block of sufficient size exists. The behavior is undefined unless 1 <= numPools and 1 <= maxBlocksPerChunk. Note that, on platforms where 8 < bsls::AlignmentUtil::BSLS_MAX_ALIGNMENT, excess memory may be allocated for pools managing smaller blocks. Also note that maxBlocksPerChunk need not be an integral power of 2; if geometric growth would exceed the maximum value, the chunk size is capped at that value).

◆ ConcurrentMultipoolAllocator() [6/9]

bdlma::ConcurrentMultipoolAllocator::ConcurrentMultipoolAllocator ( int  numPools,
const bsls::BlockGrowth::Strategy growthStrategyArray,
bslma::Allocator basicAllocator = 0 
)
inline

◆ ConcurrentMultipoolAllocator() [7/9]

bdlma::ConcurrentMultipoolAllocator::ConcurrentMultipoolAllocator ( int  numPools,
const bsls::BlockGrowth::Strategy growthStrategyArray,
int  maxBlocksPerChunk,
bslma::Allocator basicAllocator = 0 
)
inline

◆ ConcurrentMultipoolAllocator() [8/9]

bdlma::ConcurrentMultipoolAllocator::ConcurrentMultipoolAllocator ( int  numPools,
bsls::BlockGrowth::Strategy  growthStrategy,
const int *  maxBlocksPerChunkArray,
bslma::Allocator basicAllocator = 0 
)
inline

◆ ConcurrentMultipoolAllocator() [9/9]

bdlma::ConcurrentMultipoolAllocator::ConcurrentMultipoolAllocator ( int  numPools,
const bsls::BlockGrowth::Strategy growthStrategyArray,
const int *  maxBlocksPerChunkArray,
bslma::Allocator basicAllocator = 0 
)
inline

Create a multipool allocator having the specified numPools, indicating the number of internally created Pool objects; the block size of the first pool is 8 bytes, with the block size of each additional pool successively doubling. Optionally specify a growthStrategy indicating whether the number of blocks allocated at once for every internally created Pool should be either fixed or grow geometrically, starting with 1. If growthStrategy is not specified, optionally specify growthStrategyArray, indicating the strategies for each individual Pool created by this object. If neither growthStrategy nor growthStrategyArray are specified, the allocation strategy for each internally created Pool object will grow geometrically, starting from 1. Optionally specify a maxBlocksPerChunk, indicating the maximum number of blocks to be allocated at once when a pool must be replenished. If maxBlocksPerChunk is not specified, optionally specify maxBlocksPerChunkArray, indicating the maximum number of blocks to allocate at once for each individually created Pool object. If neither maxBlocksPerChunk nor maxBlocksPerChunkArray are specified, an implementation-defined value is used. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used. Memory allocation (and deallocation) requests will be satisfied using the internally maintained pool managing memory blocks of the smallest size not less than the requested size, or directly from the underlying allocator (supplied at construction), if no internally pool managing memory block of sufficient size exists. The behavior is undefined unless 1 <= numPools, growthStrategyArray has at least numPools strategies, 1 <= maxBlocksPerChunk and maxBlocksPerChunkArray have at least numPools positive values. Note that, on platforms where 8 < bsls::AlignmentUtil::BSLS_MAX_ALIGNMENT, excess memory may be allocated for pools managing smaller blocks. Also note that the maximum need not be an integral power of 2; if geometric growth would exceed a maximum value, the chunk size is capped at that value).

◆ ~ConcurrentMultipoolAllocator()

bdlma::ConcurrentMultipoolAllocator::~ConcurrentMultipoolAllocator ( )

Destroy this multipool allocator. All memory allocated from this allocator is released.

Member Function Documentation

◆ allocate()

void * bdlma::ConcurrentMultipoolAllocator::allocate ( bsls::Types::size_type  size)
virtual

Return the address of a contiguous block of maximally aligned memory of (at least) the specified size (in bytes). If size is 0, no memory is allocated and 0 is returned. If size > maxPooledBlockSize(), the memory allocation is managed directly by the underlying allocator, but will not be pooled . The behavior is undefined unless 0 <= size.

Implements bslma::Allocator.

◆ deallocate()

void bdlma::ConcurrentMultipoolAllocator::deallocate ( void *  address)
virtual

Relinquish the memory block at the specified address back to this allocator for reuse. If address is 0, this method has no effect. The behavior is undefined unless address was allocated by this allocator, and has not already been deallocated.

Implements bslma::Allocator.

◆ maxPooledBlockSize()

bsls::Types::size_type bdlma::ConcurrentMultipoolAllocator::maxPooledBlockSize ( ) const
inline

Return the maximum size of memory blocks that are pooled by this multipool object. Note that the maximum value is defined as:

2 ^ (numPools + 2)
int numPools() const
Return the number of pools managed by this multipool allocator.
Definition bdlma_concurrentmultipoolallocator.h:612

where numPools is either specified at construction, or an implementation-defined value.

◆ numPools()

int bdlma::ConcurrentMultipoolAllocator::numPools ( ) const
inline

◆ release()

void bdlma::ConcurrentMultipoolAllocator::release ( )
virtual

Relinquish all memory currently allocated through this multipool allocator.

Implements bdlma::ManagedAllocator.

◆ reserveCapacity()

void bdlma::ConcurrentMultipoolAllocator::reserveCapacity ( bsls::Types::size_type  size,
int  numObjects 
)
inline

Reserve memory from this multipool allocator to satisfy memory requests for at least the specified numObjects having the specified size (in bytes) before the pool replenishes. If size is 0, this method has no effect. The behavior is undefined unless size <= maxPooledBlockSize() and 0 <= numObjects.


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