BDE 4.14.0 Production release
|
#include <bdlma_sequentialallocator.h>
Additional Inherited Members | |
Public Types inherited from bslma::Allocator | |
typedef std::size_t | size_type |
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 |
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.
|
inlineexplicit |
|
inlineexplicit |
|
inlineexplicit |
|
inline |
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.
|
inlineexplicit |
|
inlineexplicit |
|
inline |
|
inline |
|
inline |
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.
|
inline |
|
inline |
|
inline |
|
inline |
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
.
bdlma::SequentialAllocator::~SequentialAllocator | ( | ) |
Destroy this sequential allocator. All memory allocated from this allocator is released.
|
inlinevirtual |
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.
Implements bslma::Allocator.
|
inline |
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.
|
inlinevirtual |
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.
|
inlinevirtual |
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.
|
inline |
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.
|
inlinevirtual |
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.
|
inline |
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
.