Quick Links: |
#include <bslma_sequentialallocator.h>
Public Types | |
typedef bsls::Types::size_type | size_type |
Public Member Functions | |
SequentialAllocator (Allocator *basicAllocator=0) | |
SequentialAllocator (BufferAllocator::AlignmentStrategy strategy, Allocator *basicAllocator=0) | |
SequentialAllocator (int initialSize, Allocator *basicAllocator=0) | |
SequentialAllocator (int initialSize, BufferAllocator::AlignmentStrategy strategy, Allocator *basicAllocator=0) | |
SequentialAllocator (char *buffer, int bufferSize, Allocator *basicAllocator=0) | |
SequentialAllocator (char *buffer, int bufferSize, BufferAllocator::AlignmentStrategy strategy, Allocator *basicAllocator=0) | |
SequentialAllocator (int initialSize, int maxBufferSize, Allocator *basicAllocator=0) | |
SequentialAllocator (int initialSize, int maxBufferSize, BufferAllocator::AlignmentStrategy strategy, Allocator *basicAllocator=0) | |
SequentialAllocator (char *buffer, int bufferSize, int maxBufferSize, Allocator *basicAllocator=0) | |
SequentialAllocator (char *buffer, int bufferSize, int maxBufferSize, BufferAllocator::AlignmentStrategy strategy, Allocator *basicAllocator=0) | |
virtual | ~SequentialAllocator () |
virtual void * | allocate (size_type numBytes) |
void * | allocateAndExpand (int *size) |
void * | allocateAndExpand (int *size, int maxNumBytes) |
virtual void | deallocate (void *address) |
int | expand (void *address, int originalNumBytes) |
int | expand (void *address, int originalNumBytes, int maxNumBytes) |
virtual void | release () |
virtual void | reserveCapacity (int numBytes) |
int | truncate (void *address, int originalNumBytes, int newNumBytes) |
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 () |
This class implements the ManagedAllocator
protocol to provide a fast allocator of arbitrarily-sized blocks of memory. Both the release
method and the destructor atomically delete all memory managed by this allocator; the deallocate
method, however, has no effect for this class.
See Component bslma_sequentialallocator
typedef bsls::Types::size_type bslma::Allocator::size_type [inherited] |
Reimplemented in bdlma::ConcurrentPoolAllocator.
bslma::SequentialAllocator::SequentialAllocator | ( | Allocator * | basicAllocator = 0 |
) | [explicit] |
bslma::SequentialAllocator::SequentialAllocator | ( | BufferAllocator::AlignmentStrategy | strategy, | |
Allocator * | basicAllocator = 0 | |||
) | [explicit] |
bslma::SequentialAllocator::SequentialAllocator | ( | int | initialSize, | |
Allocator * | basicAllocator = 0 | |||
) | [explicit] |
bslma::SequentialAllocator::SequentialAllocator | ( | int | initialSize, | |
BufferAllocator::AlignmentStrategy | strategy, | |||
Allocator * | basicAllocator = 0 | |||
) |
Create a sequential allocator for allocating memory blocks from an internal buffer. Optionally specify an alignment strategy
used to align allocated memory blocks. If strategy
is not specified, Natural Alignment is used. Optionally specify an initialSize
the absolute value of which indicates the initial size (in bytes) for the internal buffer. If initialSize
is not specified, an implementation-defined value is used. Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used. If an allocate
or reserveCapacity
request cannot be satisfied from the current buffer, a new buffer is allocated, the size of which is determined by a buffer growth strategy implied by initialSize
. If initialSize
was specified and is negative, or if it was not specified, the buffer growth strategy used is Geometric Growth; otherwise it is Constant Growth. (See the component level documentation for further details.) In either case, the new buffer will have sufficient capacity to satisfy the request. If *Geometric Growth* is in effect, no limit is imposed on the size of buffers.
bslma::SequentialAllocator::SequentialAllocator | ( | char * | buffer, | |
int | bufferSize, | |||
Allocator * | basicAllocator = 0 | |||
) |
bslma::SequentialAllocator::SequentialAllocator | ( | char * | buffer, | |
int | bufferSize, | |||
BufferAllocator::AlignmentStrategy | strategy, | |||
Allocator * | basicAllocator = 0 | |||
) |
Create a sequential allocator for allocating memory blocks initially from the specified buffer
the size (in bytes) of which is indicated by the absolute value of the specified bufferSize
. Optionally specify an alignment strategy
used to align allocated memory blocks. If strategy
is not specified, Natural Alignment is used. Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used. If an allocate
or reserveCapacity
request cannot be satisfied from the current buffer, a new buffer is allocated, the size of which is determined by a buffer growth strategy implied by bufferSize
. If bufferSize
is negative, the buffer growth strategy used is Geometric Growth; otherwise it is Constant Growth. (See the component level documentation for further details.) In either case, the new buffer will have sufficient capacity to satisfy the request. If Geometric Growth is in effect, no limit is imposed on the size of buffers.
bslma::SequentialAllocator::SequentialAllocator | ( | int | initialSize, | |
int | maxBufferSize, | |||
Allocator * | basicAllocator = 0 | |||
) |
bslma::SequentialAllocator::SequentialAllocator | ( | int | initialSize, | |
int | maxBufferSize, | |||
BufferAllocator::AlignmentStrategy | strategy, | |||
Allocator * | basicAllocator = 0 | |||
) |
Create a sequential allocator for allocating memory blocks from an internal buffer the initial size (in bytes) of which is indicated by the absolute value of the specified initialSize
. The specified maxBufferSize
indicates the maximum size (in bytes) allowed for internally allocated buffers. Optionally specify an alignment strategy
used to align allocated memory blocks. If strategy
is not specified, Natural Alignment is used. Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used. If an allocate
or reserveCapacity
request cannot be satisfied from the current buffer, a new buffer is allocated, the size of which is determined by a buffer growth strategy implied by initialSize
. If initialSize
is negative, the buffer growth strategy used is Geometric Growth; otherwise it is Constant Growth. (See the component level documentation for further details.) In either case, the new buffer will have sufficient capacity to satisfy the request. If Geometric Growth is in effect, the geometric progression of buffer sizes is capped at maxBufferSize
. The behavior is undefined unless 0 < maxBufferSize
, and |initialSize| <= maxBufferSize
. Note that maxBufferSize
is ignored if initialSize > 0
. Also note that maxBufferSize
may be overridden by a sufficiently large value passed to allocate
or reserveCapacity
.
bslma::SequentialAllocator::SequentialAllocator | ( | char * | buffer, | |
int | bufferSize, | |||
int | maxBufferSize, | |||
Allocator * | basicAllocator = 0 | |||
) |
bslma::SequentialAllocator::SequentialAllocator | ( | char * | buffer, | |
int | bufferSize, | |||
int | maxBufferSize, | |||
BufferAllocator::AlignmentStrategy | strategy, | |||
Allocator * | basicAllocator = 0 | |||
) |
Create a sequential allocator for allocating memory blocks initially from the specified buffer
the size (in bytes) of which is indicated by the absolute value of the specified bufferSize
. The specified maxBufferSize
indicates the maximum size (in bytes) allowed for internally allocated buffers. Optionally specify an alignment strategy
used to align allocated memory blocks. If strategy
is not specified, Natural Alignment is used. Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used. If an allocate
or reserveCapacity
request cannot be satisfied from the current buffer, a new buffer is allocated, the size of which is determined by a buffer growth strategy implied by bufferSize
. If bufferSize
is negative, the buffer growth strategy used is Geometric Growth; otherwise it is *Constant Growth*. (See the component level documentation for further details.) In either case, the new buffer will have sufficient capacity to satisfy the request. If Geometric Growth is in effect, the geometric progression of buffer sizes is capped at maxBufferSize
. The behavior is undefined unless 0 < maxBufferSize
, and |bufferSize| <= maxBufferSize
. Note that maxBufferSize
is ignored if bufferSize > 0
. Also note that maxBufferSize
may be overridden by a sufficiently large value passed to allocate
or reserveCapacity
.
virtual bslma::SequentialAllocator::~SequentialAllocator | ( | ) | [virtual] |
Destroy this sequential allocator and release all associated memory.
virtual void* bslma::SequentialAllocator::allocate | ( | size_type | numBytes | ) | [virtual] |
Return a newly allocated block of memory of (at least) the specified positive size
(bytes). If size
is 0, a null pointer is returned with no effect. The behavior is undefined unless 0 <= size
. Note that the alignment of the address returned is the maximum alignment for any fundamental type defined for the calling platform.
Implements bslma::Allocator.
void* bslma::SequentialAllocator::allocateAndExpand | ( | int * | size | ) |
Return memory of at least the specified *size
and return the actual amount of memory allocated in *size
. If *size
is 0, no memory is allocated and 0 is returned. The behavior is undefined unless 0 <= *size
.
void* bslma::SequentialAllocator::allocateAndExpand | ( | int * | size, | |
int | maxNumBytes | |||
) |
Return memory of at least the specified *size
and at most the specified maxNumBytes
. Also return the actual amount of memory allocated in *size
. If *size
is 0, no memory is allocated and 0 is returned. The behavior is undefined unless 0 <= *size <= maxNumBytes
.
virtual void bslma::SequentialAllocator::deallocate | ( | void * | address | ) | [virtual] |
This method has no effect for this allocator.
Implements bslma::Allocator.
int bslma::SequentialAllocator::expand | ( | void * | address, | |
int | originalNumBytes | |||
) |
Increase the amount of memory allocated at the specified address
from the specified originalNumBytes
to the maximum amount easily obtainable. Return the amount of memory available at address
after the expansion. The behavior is undefined unless the call to this allocator that provided the address
was performed with the originalNumBytes
. Note that this function will not expand the memory unless there have been no allocations since the allocation for originalNumBytes
.
int bslma::SequentialAllocator::expand | ( | void * | address, | |
int | originalNumBytes, | |||
int | maxNumBytes | |||
) |
Increase the amount of memory allocated at the specified address
from the specified originalNumBytes
to the maximum amount easily obtainable up to the specified maxNumBytes
. Return the amount of memory available at address
after the expansion. The behavior is undefined unless the call to this allocator that provided the address
was performed with the originalNumBytes
and originalNumBytes < maxNumBytes
. Note that this function will not expand the memory unless there have been no allocations since the allocation for originalNumBytes
.
virtual void bslma::SequentialAllocator::release | ( | ) | [virtual] |
Release all memory currently allocated through this allocator.
Implements bslma::ManagedAllocator.
virtual void bslma::SequentialAllocator::reserveCapacity | ( | int | numBytes | ) | [virtual] |
Reserve sufficient memory to satisfy allocation requests for at least the specified numBytes
without replenishment (i.e., without internal allocation). The behavior is undefined unless 0 <= numBytes
.
int bslma::SequentialAllocator::truncate | ( | void * | address, | |
int | originalNumBytes, | |||
int | newNumBytes | |||
) |
Reduce the amount of memory allocated at the specified address
from the specified originalNumBytes
to the specified newNumBytes
. Return the amount of memory available at address
after the truncation. The behavior is undefined unless the call to this allocator that provided the address
was performed with the originalNumBytes
and newNumBytes <= originalNumBytes
. Note that this function will not truncate the memory unless there have been no allocations since the allocation for originalNumBytes
.
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.
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.
void bslma::Allocator::deleteObject | ( | bsl::nullptr_t | ) | [inherited] |
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.
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.
void bslma::Allocator::deleteObjectRaw | ( | bsl::nullptr_t | ) | [inherited] |
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.