Quick Links:

bal | bbl | bdl | bsl

Classes | Public Member Functions

bdlma::SequentialPool Class Reference

#include <bdlma_sequentialpool.h>

List of all members.

Classes

struct  Block

Public Member Functions

 SequentialPool (bslma::Allocator *basicAllocator=0)
 SequentialPool (bsls::BlockGrowth::Strategy growthStrategy, bslma::Allocator *basicAllocator=0)
 SequentialPool (bsls::Alignment::Strategy alignmentStrategy, bslma::Allocator *basicAllocator=0)
 SequentialPool (bsls::BlockGrowth::Strategy growthStrategy, bsls::Alignment::Strategy alignmentStrategy, bslma::Allocator *basicAllocator=0)
 SequentialPool (int initialSize)
 SequentialPool (bsls::Types::size_type initialSize, bslma::Allocator *basicAllocator=0)
 SequentialPool (bsls::Types::size_type initialSize, bsls::BlockGrowth::Strategy growthStrategy, bslma::Allocator *basicAllocator=0)
 SequentialPool (bsls::Types::size_type initialSize, bsls::Alignment::Strategy alignmentStrategy, bslma::Allocator *basicAllocator=0)
 SequentialPool (bsls::Types::size_type initialSize, bsls::BlockGrowth::Strategy growthStrategy, bsls::Alignment::Strategy alignmentStrategy, bslma::Allocator *basicAllocator=0)
 SequentialPool (bsls::Types::size_type initialSize, bsls::Types::size_type maxBufferSize, bslma::Allocator *basicAllocator=0)
 SequentialPool (bsls::Types::size_type initialSize, bsls::Types::size_type maxBufferSize, bsls::BlockGrowth::Strategy growthStrategy, bslma::Allocator *basicAllocator=0)
 SequentialPool (bsls::Types::size_type initialSize, bsls::Types::size_type maxBufferSize, bsls::Alignment::Strategy alignmentStrategy, bslma::Allocator *basicAllocator=0)
 SequentialPool (bsls::Types::size_type initialSize, bsls::Types::size_type maxBufferSize, bsls::BlockGrowth::Strategy growthStrategy, bsls::Alignment::Strategy alignmentStrategy, bslma::Allocator *basicAllocator=0)
 SequentialPool (bsls::Types::size_type initialSize, bsls::Types::size_type maxBufferSize, bsls::BlockGrowth::Strategy growthStrategy, bsls::Alignment::Strategy alignmentStrategy, bool allocateInitialBuffer, bslma::Allocator *basicAllocator=0)
 ~SequentialPool ()
void * allocate (bsls::Types::size_type size)
void * allocateAndExpand (bsls::Types::size_type *size)
template<class TYPE >
void deleteObjectRaw (const TYPE *object)
template<class TYPE >
void deleteObject (const TYPE *object)
void release ()
void rewind ()
void reserveCapacity (bsls::Types::size_type numBytes)
bsls::Types::size_type truncate (void *address, bsls::Types::size_type originalSize, bsls::Types::size_type newSize)
bslma::Allocatorallocator () const

Detailed Description

This class implements a fast memory pool that efficiently dispenses heterogeneous blocks of memory (of varying, user-specified sizes) from a sequence of dynamically-allocated internal buffers. Memory for the internal buffers is supplied by an (optional) allocator supplied at construction; if no allocator is supplied, the currently installed default allocator is used. If an allocation exceeds the remaining free memory space in the current buffer, the pool replenishes its internal buffer with new memory to satisfy the request. This class is exception neutral: If memory cannot be allocated, the behavior is defined by the (optional) allocator specified at construction.

See Component bdlma_sequentialpool


Constructor & Destructor Documentation

bdlma::SequentialPool::SequentialPool ( bslma::Allocator basicAllocator = 0  )  [explicit]
bdlma::SequentialPool::SequentialPool ( bsls::BlockGrowth::Strategy  growthStrategy,
bslma::Allocator basicAllocator = 0 
) [explicit]
bdlma::SequentialPool::SequentialPool ( bsls::Alignment::Strategy  alignmentStrategy,
bslma::Allocator basicAllocator = 0 
) [explicit]
bdlma::SequentialPool::SequentialPool ( bsls::BlockGrowth::Strategy  growthStrategy,
bsls::Alignment::Strategy  alignmentStrategy,
bslma::Allocator basicAllocator = 0 
)

Create a sequential pool for allocating memory blocks from a sequence of dynamically-allocated buffers. Optionally specify a basicAllocator used to supply memory for the dynamically-allocated buffers. If basicAllocator is 0, the currently installed default allocator is used. Optionally specify a growthStrategy used to control buffer growth. If no growthStrategy is specified, geometric growth is used. Optionally specify an alignmentStrategy used to control alignment of allocated memory blocks. If no alignmentStrategy is specified, natural alignment is used. An implementation-defined value is used as the initial size of the internal buffer. Note that no limit is imposed on the size of the internal buffers when geometric growth is used. Also note that when constant growth is used, the size of the internal buffers will always be the same as the implementation-defined value.

bdlma::SequentialPool::SequentialPool ( int  initialSize  )  [explicit]
bdlma::SequentialPool::SequentialPool ( bsls::Types::size_type  initialSize,
bslma::Allocator basicAllocator = 0 
) [explicit]
bdlma::SequentialPool::SequentialPool ( bsls::Types::size_type  initialSize,
bsls::BlockGrowth::Strategy  growthStrategy,
bslma::Allocator basicAllocator = 0 
)
bdlma::SequentialPool::SequentialPool ( bsls::Types::size_type  initialSize,
bsls::Alignment::Strategy  alignmentStrategy,
bslma::Allocator basicAllocator = 0 
)
bdlma::SequentialPool::SequentialPool ( bsls::Types::size_type  initialSize,
bsls::BlockGrowth::Strategy  growthStrategy,
bsls::Alignment::Strategy  alignmentStrategy,
bslma::Allocator basicAllocator = 0 
)

Create a sequential pool for allocating memory blocks from a sequence of dynamically-allocated buffers, of which the initial buffer has the specified initialSize (in bytes). Optionally specify a basicAllocator used to supply memory for the dynamically-allocated buffers. If basicAllocator is 0, the currently installed default allocator is used. Optionally specify a growthStrategy used to control buffer growth. If no growthStrategy is specified, geometric growth is used. Optionally specify an alignmentStrategy used to control alignment of allocated memory blocks. If no alignmentStrategy is specified, natural alignment is used. By specifying an initialSize, the construction of a sequential pool will incur a memory allocation. The behavior is undefined unless 0 < initialSize. Note that no limit is imposed on the size of the internal buffers when geometric growth is used. Also note that when constant growth is used, the size of the internal buffers will always be the same as initialSize. Also note that SequentialPool(int initialSize) is provided to avoid ambiguous definitions.

bdlma::SequentialPool::SequentialPool ( bsls::Types::size_type  initialSize,
bsls::Types::size_type  maxBufferSize,
bslma::Allocator basicAllocator = 0 
)
bdlma::SequentialPool::SequentialPool ( bsls::Types::size_type  initialSize,
bsls::Types::size_type  maxBufferSize,
bsls::BlockGrowth::Strategy  growthStrategy,
bslma::Allocator basicAllocator = 0 
)
bdlma::SequentialPool::SequentialPool ( bsls::Types::size_type  initialSize,
bsls::Types::size_type  maxBufferSize,
bsls::Alignment::Strategy  alignmentStrategy,
bslma::Allocator basicAllocator = 0 
)
bdlma::SequentialPool::SequentialPool ( bsls::Types::size_type  initialSize,
bsls::Types::size_type  maxBufferSize,
bsls::BlockGrowth::Strategy  growthStrategy,
bsls::Alignment::Strategy  alignmentStrategy,
bslma::Allocator basicAllocator = 0 
)

Create a sequential pool for allocating memory blocks from a sequence of dynamically-allocated buffers, of which the initial buffer has the specified initialSize (in bytes), and the internal buffer growth is limited to the specified maxBufferSize. Optionally specify a basicAllocator used to supply memory for the dynamically-allocated buffers. If basicAllocator is 0, the currently installed default allocator is used. Optionally specify a growthStrategy used to control buffer growth. If no growthStrategy is specified, geometric growth is used. Optionally specify an alignmentStrategy used to control alignment of allocated memory blocks. If no alignmentStrategy is specified, natural alignment is used. The behavior is undefined unless 0 < initialSize and initialSize <= maxBufferSize. Note that when constant growth is used, the size of the internal buffers will always be the same as initialSize.

bdlma::SequentialPool::SequentialPool ( bsls::Types::size_type  initialSize,
bsls::Types::size_type  maxBufferSize,
bsls::BlockGrowth::Strategy  growthStrategy,
bsls::Alignment::Strategy  alignmentStrategy,
bool  allocateInitialBuffer,
bslma::Allocator basicAllocator = 0 
)

Create a sequential pool for allocating memory blocks from a sequence of dynamically-allocated buffers, of which the initial buffer has the specified initialSize (in bytes), the internal buffer growth is limited to the specified maxBufferSize, the specified growthStrategy is used to control buffer growth, and the specified alignmentStrategy is used to control alignment of allocated memory blocks. Allocate the initial buffer only if the specified allocateInitialBuffer is true. Optionally specify a basicAllocator used to supply memory for the dynamically-allocated buffers. If basicAllocator is 0, the currently installed default allocator is used. The behavior is undefined unless 0 < initialSize and initialSize <= maxBufferSize. Note that when constant growth is used, the size of the internal buffers will always be the same as initialSize.

bdlma::SequentialPool::~SequentialPool (  ) 

Destroy this sequential pool. All memory allocated by this pool is released.


Member Function Documentation

void* bdlma::SequentialPool::allocate ( bsls::Types::size_type  size  ) 

Return the address of a contiguous block of memory of the specified size (in bytes) according to the alignment strategy specified at construction. If size is 0, no memory is allocated and 0 is returned. If the allocation request exceeds the remaining free memory space in the current internal buffer, use the allocator supplied at construction to allocate a new internal buffer, then allocate memory from the new buffer.

void* bdlma::SequentialPool::allocateAndExpand ( bsls::Types::size_type size  ) 

Return the address of a contiguous block of memory of at least the specified *size (in bytes), and load the actual amount of memory allocated in *size. If *size is 0, return 0 with no effect. If the allocation request exceeds the remaining free memory space in the current internal buffer, use the allocator supplied at construction to allocate a new internal buffer, then allocate memory from the new buffer.

template<class TYPE >
void bdlma::SequentialPool::deleteObjectRaw ( const TYPE *  object  ) 

Destroy the specified object. Note that memory associated with object is not deallocated because there is no deallocate method in SequentialPool.

template<class TYPE >
void bdlma::SequentialPool::deleteObject ( const TYPE *  object  ) 

Destroy the specified object. Note that this method has the same effect as the deleteObjectRaw method (since no deallocation is involved), and exists for consistency across pools.

void bdlma::SequentialPool::release (  ) 

Release all memory allocated through this pool and return to the underlying allocator all memory. The pool is reset to its default-constructed state, retaining the alignment and growth strategies, and the initial and maximum buffer sizes in effect following construction. The effect of subsequently - to this invokation of release - using a pointer obtained from this object prior to this call to release is undefined.

void bdlma::SequentialPool::rewind (  ) 

Release all memory allocated through this pool and return to the underlying allocator only memory that was allocated outside of the typical internal buffer growth of this pool (i.e., large blocks). All retained memory will be used to satisfy subsequent allocations. The effect of subsequently - to this invokation of rewind - using a pointer obtained from this object prior to this call to rewind is undefined.

void bdlma::SequentialPool::reserveCapacity ( bsls::Types::size_type  numBytes  ) 

Reserve sufficient memory to satisfy allocation requests for at least the specified numBytes without replenishment (i.e., without dynamic allocation). If numBytes is 0, no memory is reserved. Note that, when the numBytes is distributed over multiple allocate requests - due to alignment effects - it is possible that not all numBytes of memory will be used for allocation before triggering dynamic allocation.

bsls::Types::size_type bdlma::SequentialPool::truncate ( void *  address,
bsls::Types::size_type  originalSize,
bsls::Types::size_type  newSize 
)

Reduce the amount of memory allocated at the specified address of the specified originalSize (in bytes) to the specified newSize. Return newSize after truncating, or originalSize if the memory block at address cannot be truncated. This method can only truncate the memory block returned by the most recent allocate request from this memory pool, and otherwise has no effect. The behavior is undefined unless the memory block at address was originally allocated by this memory pool, the size of the memory block at address is originalSize, newSize <= originalSize, and release was not called after allocating the memory block at address.

bslma::Allocator* bdlma::SequentialPool::allocator (  )  const

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.


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