List of all members.
Public Types |
typedef bsls::Types::size_type | size_type |
Public Member Functions |
| SequentialAllocator (bslma::Allocator *basicAllocator=0) |
| SequentialAllocator (bsls::BlockGrowth::Strategy growthStrategy, bslma::Allocator *basicAllocator=0) |
| SequentialAllocator (bsls::Alignment::Strategy alignmentStrategy, bslma::Allocator *basicAllocator=0) |
| SequentialAllocator (bsls::BlockGrowth::Strategy growthStrategy, bsls::Alignment::Strategy alignmentStrategy, bslma::Allocator *basicAllocator=0) |
| SequentialAllocator (int initialSize) |
| SequentialAllocator (bsls::Types::size_type initialSize, bslma::Allocator *basicAllocator=0) |
| SequentialAllocator (bsls::Types::size_type initialSize, bsls::BlockGrowth::Strategy growthStrategy, bslma::Allocator *basicAllocator=0) |
| SequentialAllocator (bsls::Types::size_type initialSize, bsls::Alignment::Strategy alignmentStrategy, bslma::Allocator *basicAllocator=0) |
| SequentialAllocator (bsls::Types::size_type initialSize, bsls::BlockGrowth::Strategy growthStrategy, bsls::Alignment::Strategy alignmentStrategy, bslma::Allocator *basicAllocator=0) |
| SequentialAllocator (bsls::Types::size_type initialSize, bsls::Types::size_type maxBufferSize, bslma::Allocator *basicAllocator=0) |
| SequentialAllocator (bsls::Types::size_type initialSize, bsls::Types::size_type maxBufferSize, bsls::BlockGrowth::Strategy growthStrategy, bslma::Allocator *basicAllocator=0) |
| SequentialAllocator (bsls::Types::size_type initialSize, bsls::Types::size_type maxBufferSize, bsls::Alignment::Strategy alignmentStrategy, bslma::Allocator *basicAllocator=0) |
| SequentialAllocator (bsls::Types::size_type initialSize, bsls::Types::size_type maxBufferSize, bsls::BlockGrowth::Strategy growthStrategy, bsls::Alignment::Strategy alignmentStrategy, bslma::Allocator *basicAllocator=0) |
virtual | ~SequentialAllocator () |
virtual void * | allocate (bsls::Types::size_type size) |
void * | allocateAndExpand (bsls::Types::size_type *size) |
virtual void | deallocate (void *address) |
virtual void | release () |
virtual 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) |
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 () |
Detailed Description
This class implements the ManagedAllocator
protocol to provide a fast allocator that dispenses heterogeneous blocks of memory (of varying, user-specified sizes) from a sequence of dynamically-allocated 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 allocator 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_sequentialallocator
Member Typedef Documentation
Constructor & Destructor Documentation
bdlma::SequentialAllocator::SequentialAllocator |
( |
bslma::Allocator * |
basicAllocator = 0 |
) |
[explicit] |
Create a sequential allocator 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. Note that no limit is imposed on the size of the internal buffers when geometric growth is used.
bdlma::SequentialAllocator::SequentialAllocator |
( |
int |
initialSize |
) |
[explicit] |
Create a sequential allocator 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. An implementation-defined value is used as the initial size of the internal buffer. 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 the implementation-defined value. Also note that SequentialAllocator(int initialSize)
is provided to avoid ambiguous definitions.
Create a sequential allocator for allocating memory blocks from a sequence of dynamically-allocated buffers, of which the initial buffer has the specified initialSize
(in bytes), and the 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
.
virtual bdlma::SequentialAllocator::~SequentialAllocator |
( |
|
) |
[virtual] |
Destroy this sequential allocator. All memory allocated from this allocator is released.
Member Function Documentation
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.
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 into *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.
virtual void bdlma::SequentialAllocator::deallocate |
( |
void * |
address |
) |
[virtual] |
This method has no effect on the memory block at the specified address
as all memory allocated by this allocator is managed. The behavior is undefined unless address
is 0, or was allocated by this allocator and has not already been deallocated.
Implements bslma::Allocator.
virtual void bdlma::SequentialAllocator::release |
( |
|
) |
[virtual] |
Release all memory allocated through this allocator and return to the underlying allocator all memory. The allocator 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.
Implements bdlma::ManagedAllocator.
virtual void bdlma::SequentialAllocator::rewind |
( |
|
) |
[virtual] |
Release all memory allocated through this allocator and return to the underlying allocator only memory that was allocated outside of the typical internal buffer growth of this allocator (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.
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.
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 allocator, and otherwise has no effect. The behavior is undefined unless the memory block at address
was originally allocated by this allocator, the size of the memory block at address
is originalSize
, newSize <= originalSize
, and release
was not called after allocating the memory block at address
.
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 >.
template<class TYPE >
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.
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.
template<class TYPE >
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.
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.
The documentation for this class was generated from the following file: