Quick Links: |
#include <bdlma_multipoolallocator.h>
Public Types | |
typedef bsls::Types::size_type | size_type |
Public Member Functions | |
MultipoolAllocator (bslma::Allocator *basicAllocator=0) | |
MultipoolAllocator (int numPools, bslma::Allocator *basicAllocator=0) | |
MultipoolAllocator (bsls::BlockGrowth::Strategy growthStrategy, bslma::Allocator *basicAllocator=0) | |
MultipoolAllocator (int numPools, bsls::BlockGrowth::Strategy growthStrategy, bslma::Allocator *basicAllocator=0) | |
MultipoolAllocator (int numPools, bsls::BlockGrowth::Strategy growthStrategy, int maxBlocksPerChunk, bslma::Allocator *basicAllocator=0) | |
MultipoolAllocator (int numPools, const bsls::BlockGrowth::Strategy *growthStrategyArray, bslma::Allocator *basicAllocator=0) | |
MultipoolAllocator (int numPools, const bsls::BlockGrowth::Strategy *growthStrategyArray, int maxBlocksPerChunk, bslma::Allocator *basicAllocator=0) | |
MultipoolAllocator (int numPools, bsls::BlockGrowth::Strategy growthStrategy, const int *maxBlocksPerChunkArray, bslma::Allocator *basicAllocator=0) | |
MultipoolAllocator (int numPools, const bsls::BlockGrowth::Strategy *growthStrategyArray, const int *maxBlocksPerChunkArray, bslma::Allocator *basicAllocator=0) | |
virtual | ~MultipoolAllocator () |
void | reserveCapacity (bsls::Types::size_type size, int numObjects) |
virtual void * | allocate (bsls::Types::size_type size) |
virtual void | deallocate (void *address) |
virtual void | release () |
int | numPools () const |
bsls::Types::size_type | maxPooledBlockSize () const |
virtual void * | allocate (size_type size)=0 |
template<class TYPE > | |
void | deleteObject (const TYPE *object) |
void | deleteObject (bsl::nullptr_t) |
template<class TYPE > | |
void | deleteObjectRaw (const TYPE *object) |
void | deleteObjectRaw (bsl::nullptr_t) |
Static Public Member Functions | |
static void | throwBadAlloc () |
This class implements the bdlma::ManagedAllocator
protocol to provide an allocator that maintains a configurable number of bdlma::Pool
objects, each dispensing memory blocks of a unique size. The bdlma::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 bdlma::MultipoolAllocator
release all memory currently allocated via the object.
See Component bdlma_multipoolallocator
typedef bsls::Types::size_type bslma::Allocator::size_type [inherited] |
Reimplemented in bdlma::ConcurrentPoolAllocator.
bdlma::MultipoolAllocator::MultipoolAllocator | ( | bslma::Allocator * | basicAllocator = 0 |
) | [explicit] |
bdlma::MultipoolAllocator::MultipoolAllocator | ( | int | numPools, | |
bslma::Allocator * | basicAllocator = 0 | |||
) | [explicit] |
bdlma::MultipoolAllocator::MultipoolAllocator | ( | bsls::BlockGrowth::Strategy | growthStrategy, | |
bslma::Allocator * | basicAllocator = 0 | |||
) | [explicit] |
bdlma::MultipoolAllocator::MultipoolAllocator | ( | int | numPools, | |
bsls::BlockGrowth::Strategy | growthStrategy, | |||
bslma::Allocator * | basicAllocator = 0 | |||
) |
bdlma::MultipoolAllocator::MultipoolAllocator | ( | int | numPools, | |
bsls::BlockGrowth::Strategy | growthStrategy, | |||
int | maxBlocksPerChunk, | |||
bslma::Allocator * | basicAllocator = 0 | |||
) |
Create a multipool allocator. Optionally specify numPools
, indicating the number of internally created bdlma::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 bdlma::Pool
should be either fixed or grow geometrically, starting with 1. If growthStrategy
is not specified, the allocation strategy for each internally created bdlma::Pool
object is geometric, starting from 1. If numPools
and growthStrategy
are 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 internal pool managing memory blocks 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.
bdlma::MultipoolAllocator::MultipoolAllocator | ( | int | numPools, | |
const bsls::BlockGrowth::Strategy * | growthStrategyArray, | |||
bslma::Allocator * | basicAllocator = 0 | |||
) |
bdlma::MultipoolAllocator::MultipoolAllocator | ( | int | numPools, | |
const bsls::BlockGrowth::Strategy * | growthStrategyArray, | |||
int | maxBlocksPerChunk, | |||
bslma::Allocator * | basicAllocator = 0 | |||
) |
bdlma::MultipoolAllocator::MultipoolAllocator | ( | int | numPools, | |
bsls::BlockGrowth::Strategy | growthStrategy, | |||
const int * | maxBlocksPerChunkArray, | |||
bslma::Allocator * | basicAllocator = 0 | |||
) |
bdlma::MultipoolAllocator::MultipoolAllocator | ( | int | numPools, | |
const bsls::BlockGrowth::Strategy * | growthStrategyArray, | |||
const int * | maxBlocksPerChunkArray, | |||
bslma::Allocator * | basicAllocator = 0 | |||
) |
Create a multipool allocator having the specified numPools
, indicating the number of internally created bdlma::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 bdlma::Pool
should be either fixed or grow geometrically, starting with 1. If growthStrategy
is not specified, optionally specify a growthStrategyArray
, indicating the strategies for each individual bdlma::Pool
created by this object. If neither growthStrategy
nor growthStrategyArray
is specified, the allocation strategy for each internally created bdlma::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 a maxBlocksPerChunkArray
, indicating the maximum number of blocks to allocate at once for each individually created bdlma::Pool
object. If neither maxBlocksPerChunk
nor maxBlocksPerChunkArray
is 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 internal pool managing memory blocks of sufficient size exists. The behavior is undefined unless 1 <= numPools
, growthStrategyArray
has at least numPools
strategies, 1 <= maxBlocksPerChunk
, and maxBlocksPerChunkArray
has 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.
virtual bdlma::MultipoolAllocator::~MultipoolAllocator | ( | ) | [virtual] |
Destroy this multipool allocator. All memory allocated from this allocator is released.
void bdlma::MultipoolAllocator::reserveCapacity | ( | bsls::Types::size_type | size, | |
int | numObjects | |||
) |
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
.
virtual void* bdlma::MultipoolAllocator::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 .
virtual void bdlma::MultipoolAllocator::deallocate | ( | void * | address | ) | [virtual] |
Return 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.
virtual void bdlma::MultipoolAllocator::release | ( | ) | [virtual] |
Release all memory currently allocated through this multipool allocator.
Implements bdlma::ManagedAllocator.
int bdlma::MultipoolAllocator::numPools | ( | ) | const |
Return the number of pools managed by this multipool allocator.
bsls::Types::size_type bdlma::MultipoolAllocator::maxPooledBlockSize | ( | ) | const |
Return the maximum size of memory blocks that are pooled by this multipool allocator. Note that the maximum value is defined as:
2 ^ (numPools + 2)
where numPools
is either specified at construction, or an implementation-defined value.
static void bslma::Allocator::throwBadAlloc | ( | ) | [static, inherited] |
DEPRECATED: Use bsls::BslExceptionUtil::throwBadAlloc
instead.
Throw std::bad_alloc
if exceptions are enabled or abort the program otherwise. Derived classes and helper functions will typically call this function when they are unable to satisfy an allocation request. This function never returns.
virtual void* bslma::Allocator::allocate | ( | size_type | size | ) | [pure virtual, inherited] |
Return a newly allocated block of memory of (at least) the specified positive size
(in bytes). If size
is 0, a null pointer is returned with no other effect. If this allocator cannot return the requested number of bytes, then it will throw a std::bad_alloc
exception in an exception-enabled build, or else will abort the program in a non-exception build. The behavior is undefined unless 0 <= size
. Note that the alignment of the address returned conforms to the platform requirement for any object of the specified size
.
Implemented in ball::CountingAllocator, balst::StackTraceTestAllocator, bdlma::BufferedSequentialAllocator, bslma::AllocatorAdaptor_Imp< STL_ALLOC >, bslma::BufferAllocator, bslma::MallocFreeAllocator, bslma::NewDeleteAllocator, bslma::SequentialAllocator, bslma::TestAllocator, and bslma::AllocatorAdaptor_Imp< STL_ALLOC::template rebind< char >::other >.
void bslma::Allocator::deleteObject | ( | const TYPE * | object | ) | [inherited] |
Destroy the specified object
based on its dynamic type and then use this allocator to deallocate its memory footprint. Do nothing if object
is a null pointer. The behavior is undefined unless object
, when cast appropriately to void *
, was allocated using this allocator and has not already been deallocated. Note that dynamic_cast<void *>(object)
is applied if TYPE
is polymorphic, and static_cast<void *>(object)
is applied otherwise.
void bslma::Allocator::deleteObject | ( | bsl::nullptr_t | ) | [inherited] |
This function has no effect. Note that it exists to support calling deleteObject
will a null pointer literal, that would otherwise not deduce to a pointer type for the method above. As calls to deleteObject
with (typed) null pointer values have well-defined behavior, it should also support calls with a null pointer literal.
void bslma::Allocator::deleteObjectRaw | ( | const TYPE * | object | ) | [inherited] |
Destroy the specified object
and then use this allocator to deallocate its memory footprint. Do nothing if object
is a null pointer. The behavior is undefined unless object
was allocated using this allocator, is not a secondary base class pointer -- i.e., the address is (numerically) the same as when it was originally dispensed by this allocator, and has not already been deallocated.
void bslma::Allocator::deleteObjectRaw | ( | bsl::nullptr_t | ) | [inherited] |
This function has no effect. Note that it exists to support calling deleteObjectRaw
will a null pointer literal, that would otherwise not deduce to a pointer type for the method above. As calls to deleteObjectRaw
with (typed) null pointer values have well-defined behavior, it should also support calls with a null pointer literal.