Quick Links: |
#include <bdlma_concurrentpoolallocator.h>
Classes | |
union | Header |
Public Types | |
typedef bsls::Types::size_type | size_type |
Public Member Functions | |
ConcurrentPoolAllocator (bslma::Allocator *basicAllocator=0) | |
ConcurrentPoolAllocator (bsls::BlockGrowth::Strategy growthStrategy, bslma::Allocator *basicAllocator=0) | |
ConcurrentPoolAllocator (bsls::BlockGrowth::Strategy growthStrategy, int maxBlocksPerChunk, bslma::Allocator *basicAllocator=0) | |
ConcurrentPoolAllocator (size_type blockSize, bslma::Allocator *basicAllocator=0) | |
ConcurrentPoolAllocator (size_type blockSize, bsls::BlockGrowth::Strategy growthStrategy, bslma::Allocator *basicAllocator=0) | |
ConcurrentPoolAllocator (size_type blockSize, bsls::BlockGrowth::Strategy growthStrategy, int maxBlocksPerChunk, bslma::Allocator *basicAllocator=0) | |
~ConcurrentPoolAllocator () | |
void * | allocate (size_type size) |
void | deallocate (void *address) |
void | release () |
void | reserveCapacity (int numObjects) |
size_type | blockSize () 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 bslma::Allocator
protocol to provide an allocator that manages pooled memory blocks of some uniform size, specified either at construction, or at the first invocation of the allocate
method. This allocator maintains an internal linked list of free memory blocks, and dispenses one block for each allocate
method invocation. When a memory block is deallocated, it is returned to the free list for potential reuse.
This class guarantees thread-safety while allocating or releasing memory.
See Component bdlma_concurrentpoolallocator
type for block size
Reimplemented from bslma::Allocator.
bdlma::ConcurrentPoolAllocator::ConcurrentPoolAllocator | ( | bslma::Allocator * | basicAllocator = 0 |
) | [explicit] |
bdlma::ConcurrentPoolAllocator::ConcurrentPoolAllocator | ( | bsls::BlockGrowth::Strategy | growthStrategy, | |
bslma::Allocator * | basicAllocator = 0 | |||
) | [explicit] |
bdlma::ConcurrentPoolAllocator::ConcurrentPoolAllocator | ( | bsls::BlockGrowth::Strategy | growthStrategy, | |
int | maxBlocksPerChunk, | |||
bslma::Allocator * | basicAllocator = 0 | |||
) |
Create a pool allocator that returns blocks of contiguous memory of uniform size for each allocate
method invocation, where the size is determined by the first invocation of allocate
. Optionally specify a growthStrategy
used to control the growth of internal memory chunks (from which memory blocks are dispensed). If growthStrategy
is not specified, geometric growth is used. If growthStrategy
is specified, optionally specify a maxBlocksPerChunk
, indicating the maximum number of blocks to be allocated at once when the underlying pool must be replenished. If maxBlocksPerChunk
is not specified, an implementation-defined value is used. If geometric growth is used, the chunk size grows starting at the value returned by blockSize
, doubling in size until the size is exactly blockSize() * maxBlocksPerChunk
. If constant growth is used, the chunk size is always maxBlocksPerChunk
. Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used. The behavior is undefined unless 1 <= maxBlocksPerChunk
.
bdlma::ConcurrentPoolAllocator::ConcurrentPoolAllocator | ( | size_type | blockSize, | |
bslma::Allocator * | basicAllocator = 0 | |||
) | [explicit] |
bdlma::ConcurrentPoolAllocator::ConcurrentPoolAllocator | ( | size_type | blockSize, | |
bsls::BlockGrowth::Strategy | growthStrategy, | |||
bslma::Allocator * | basicAllocator = 0 | |||
) |
bdlma::ConcurrentPoolAllocator::ConcurrentPoolAllocator | ( | size_type | blockSize, | |
bsls::BlockGrowth::Strategy | growthStrategy, | |||
int | maxBlocksPerChunk, | |||
bslma::Allocator * | basicAllocator = 0 | |||
) |
Create a pool allocator that returns blocks of contiguous memory of the specified blockSize
(in bytes) for each allocate
method invocation. Optionally specify a growthStrategy
used to control the growth of internal memory chunks (from which memory blocks are dispensed). If growthStrategy
is not specified, geometric growth is used. If blockSize
and growthStrategy
are specified, optionally specify a maxBlocksPerChunk
, indicating the maximum number of blocks to be allocated at once when the underlying pool must be replenished. If maxBlocksPerChunk
is not specified, an implementation-defined value is used. If geometric growth is used, the chunk size grows starting at blockSize
, doubling in size until the size is exactly blockSize * maxBlocksPerChunk
. If constant growth is used, the chunk size is always maxBlocksPerChunk
. Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used. The behavior is undefined unless 1 <= maxBlocksPerChunk
.
bdlma::ConcurrentPoolAllocator::~ConcurrentPoolAllocator | ( | ) |
Destroy this pool allocator.
void* bdlma::ConcurrentPoolAllocator::allocate | ( | size_type | size | ) |
Return a newly allocated block of memory of (at least) the specified positive size
(in bytes), and having alignment conforming to the platform requirement for any object having size
bytes. If size
is 0, a null pointer is returned with no effect. If the block size is not supplied at construction, then the size
specified in the first call to this method fixes the block size. If size
is greater than the value returned by blockSize
, the allocation request will be satisfied directly by the external allocator supplied at construction (or the default allocator, if no allocator was supplied).
void bdlma::ConcurrentPoolAllocator::deallocate | ( | void * | address | ) | [virtual] |
Return the memory at the specified address
back to this allocator. If address
is 0, this method has no effect. The behavior is undefined unless address
was allocated using this allocator and has not already been deallocated.
Implements bslma::Allocator.
void bdlma::ConcurrentPoolAllocator::release | ( | ) |
Relinquish all memory currently allocated through this pool allocator.
void bdlma::ConcurrentPoolAllocator::reserveCapacity | ( | int | numObjects | ) |
Reserve memory from this pool allocator to satisfy memory requests for at least the specified numObjects
before the pool replenishes. The behavior is undefined unless 0 <= numObjects
. Note that this operation has no effect unless block size was supplied at construction, or allocate
was invoked.
size_type bdlma::ConcurrentPoolAllocator::blockSize | ( | ) | const |
Return the size (in bytes) of the memory blocks allocated from this allocator. Note that all blocks dispensed by this allocator have the same size.
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.