|
BDE 4.39.x Production Release
|
#include <bdlma_concurrentfixedpool.h>
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).
Public Member Functions | |
| ConcurrentFixedPool (int objectSize, int poolSize, bslma::Allocator *basicAllocator=0) | |
| ~ConcurrentFixedPool () | |
| 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 |
| bslma::Allocator * | allocator () const |
| 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.
0 < objectSize, 0 < poolSize, and 0x1FFFFFF >= poolSize. | bdlma::ConcurrentFixedPool::~ConcurrentFixedPool | ( | ) |
Destroy this object and release all associated memory.
|
inline |
Return the address of the memory block identified by the specified index.
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.
|
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.
object, when cast appropriately to void *, was allocated using this allocator and has not already been deallocated. 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.
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.
address corresponds to a memory block allocated from this pool.
|
inline |
Return the size of the memory blocks allocated from this object.
|
inline |
Return the maximum size of this pool.
| void bdlma::ConcurrentFixedPool::release | ( | ) |
Release all memory currently allocated through this object.
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.
0 <= numObjects. Return 0 on success and the number of objects that could not be reserved otherwise.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.
0 <= backoffLevel.