BDE 4.14.0 Production release
|
#include <bdlma_concurrentfixedpool.h>
Public Member Functions | |
ConcurrentFixedPool (int objectSize, int poolSize, bslma::Allocator *basicAllocator=0) | |
~ConcurrentFixedPool () | |
Destroy this object and release all associated memory. | |
void * | allocate () |
void | deallocate (void *address) |
template<class TYPE > | |
void | deleteObject (const TYPE *object) |
template<class TYPE > | |
void | deleteObjectRaw (const TYPE *object) |
void | release () |
int | reserveCapacity (int numObjects) |
void | setBackoffLevel (int backoffLevel) |
int | backoffLevel () const |
int | indexFromAddress (void *address) const |
int | objectSize () const |
void * | addressFromIndex (int index) const |
int | poolSize () const |
Return the maximum size of this pool. | |
bslma::Allocator * | allocator () const |
This class implements a memory pool that allocates and manages up to a fixed number of memory blocks of some uniform size, with both the limit on the number of blocks and the block size specified at construction.
This class guarantees thread safety when allocating or releasing memory (but see the documentation for the release
method).
bdlma::ConcurrentFixedPool::ConcurrentFixedPool | ( | int | objectSize, |
int | poolSize, | ||
bslma::Allocator * | basicAllocator = 0 |
||
) |
Create a memory pool that returns memory of the specified objectSize
for each invocation of the allocate
method. Configure this pool to support allocation of up to the specified poolSize
number of memory blocks. The largest supported poolSize
is 33554431. Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used. The behavior is undefined unless 0 < objectSize
, 0 < poolSize
, and 0x1FFFFFF >= poolSize
.
bdlma::ConcurrentFixedPool::~ConcurrentFixedPool | ( | ) |
|
inline |
Return the address of the memory block identified by the specified index
. The behavior is undefined unless the index has been obtained through indexFromAddress
.
void * bdlma::ConcurrentFixedPool::allocate | ( | ) |
Allocate a memory block of the objectSize
specified at construction. Return the address of that block or 0 if the pool is exhausted (i.e., poolSize()
memory blocks have already been allocated from this pool).
|
inline |
Return the allocator used by this object to allocate memory. Note that this allocator can not be used to deallocate memory allocated through this pool.
|
inline |
Return the non-negative backoffLevel
that controls the amount of spinning that occurs when calls to this pool encounter contention.
void bdlma::ConcurrentFixedPool::deallocate | ( | void * | address | ) |
Deallocate the memory block at the specified address
back to this pool for reuse.
|
inline |
Destroy the specified object
based on its dynamic type and then use this allocator to deallocate its memory footprint. Do nothing if object
is 0. 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.
|
inline |
Destroy the specified object
based on its static type and then use this allocator to deallocate its memory footprint. Do nothing if object
is 0. The behavior is undefined if object
is a base-class pointer to a derived type, was not allocated using this allocator, or has already been deallocated.
|
inline |
Return an index in the range from 0 to the maximum size of this pool that uniquely identifies the memory block at the specified address
. The behavior is undefined unless address
corresponds to a memory block allocated from this pool.
|
inline |
Return the size of the memory blocks allocated from this object. Note that all blocks have the same size.
|
inline |
void bdlma::ConcurrentFixedPool::release | ( | ) |
Release all memory currently allocated through this object. Note that this method should only be invoked when it is known that no blocks currently allocated through this pool will be used; therefore, it is not safe to use this method if any other thread may be concurrently allocating memory from this pool. Also note that release()
is intended to free all memory without regard to the contents of that memory. Specifically, release()
can not call object destructors for any allocated objects, since it has no knowledge of their type. If object destruction is required, use ConcurrentFixedPool::deleteObject()
.
int bdlma::ConcurrentFixedPool::reserveCapacity | ( | int | numObjects | ) |
Reserve memory from this pool to satisfy memory requests for at least the specified numObjects
before the pool replenishes. The behavior is undefined unless 0 <= numObjects
. Return 0 on success and the number of objects that could not be reserved otherwise. Note that this method fails if the number of memory blocks already allocated plus numObjects
exceeds poolSize()
.
|
inline |
Configure this pool with the specified non-negative backoffLevel
that controls the amount of spinning that occurs when calls to this pool encounter contention. Setting backoffLevel
to 0 disables spinning. Greater values of backoffLevel
correspond to greater amounts of spinning. The behavior is undefined unless 0 <= backoffLevel
. Note that both contention detection and spinning strategy are implementation defined.