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

#include <bdlma_concurrentpoolallocator.h>

Inheritance diagram for bdlma::ConcurrentPoolAllocator:
bslma::Allocator bsl::memory_resource

Public Types

typedef bsls::Types::size_type size_type
 
- Public Types inherited from bslma::Allocator
typedef std::size_t 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 () BSLS_KEYWORD_OVERRIDE
 Destroy this pool allocator.
 
void * allocate (size_type size) BSLS_KEYWORD_OVERRIDE
 
void deallocate (void *address) BSLS_KEYWORD_OVERRIDE
 
void release ()
 
void reserveCapacity (int numObjects)
 
size_type blockSize () 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

- 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 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 bdlma_concurrentpoolallocator

Member Typedef Documentation

◆ size_type

Constructor & Destructor Documentation

◆ ConcurrentPoolAllocator() [1/6]

bdlma::ConcurrentPoolAllocator::ConcurrentPoolAllocator ( bslma::Allocator basicAllocator = 0)
explicit

◆ ConcurrentPoolAllocator() [2/6]

bdlma::ConcurrentPoolAllocator::ConcurrentPoolAllocator ( bsls::BlockGrowth::Strategy  growthStrategy,
bslma::Allocator basicAllocator = 0 
)
explicit

◆ ConcurrentPoolAllocator() [3/6]

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.

◆ ConcurrentPoolAllocator() [4/6]

bdlma::ConcurrentPoolAllocator::ConcurrentPoolAllocator ( size_type  blockSize,
bslma::Allocator basicAllocator = 0 
)
explicit

◆ ConcurrentPoolAllocator() [5/6]

bdlma::ConcurrentPoolAllocator::ConcurrentPoolAllocator ( size_type  blockSize,
bsls::BlockGrowth::Strategy  growthStrategy,
bslma::Allocator basicAllocator = 0 
)

◆ ConcurrentPoolAllocator() [6/6]

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.

◆ ~ConcurrentPoolAllocator()

bdlma::ConcurrentPoolAllocator::~ConcurrentPoolAllocator ( )

Member Function Documentation

◆ allocate()

void * bdlma::ConcurrentPoolAllocator::allocate ( size_type  size)
virtual

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).

Implements bslma::Allocator.

◆ blockSize()

bsls::Types::size_type bdlma::ConcurrentPoolAllocator::blockSize ( ) const
inline

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.

◆ deallocate()

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.

◆ release()

void bdlma::ConcurrentPoolAllocator::release ( )
inline

Relinquish all memory currently allocated through this pool allocator.

◆ reserveCapacity()

void bdlma::ConcurrentPoolAllocator::reserveCapacity ( int  numObjects)
inline

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.


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