BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlma::SequentialAllocator Class Reference

#include <bdlma_sequentialallocator.h>

Inheritance diagram for bdlma::SequentialAllocator:
bdlma::ManagedAllocator bslma::Allocator bsl::memory_resource

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)
 
 ~SequentialAllocator () BSLS_KEYWORD_OVERRIDE
 
void * allocate (bsls::Types::size_type size) BSLS_KEYWORD_OVERRIDE
 
void * allocateAndExpand (bsls::Types::size_type *size)
 
void deallocate (void *address) BSLS_KEYWORD_OVERRIDE
 
void release () BSLS_KEYWORD_OVERRIDE
 
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)
 
- Public Member Functions inherited from bslma::Allocator
 ~Allocator () BSLS_KEYWORD_OVERRIDE
 
template<class TYPE >
void deleteObject (const TYPE *object)
 
template<class TYPE >
void deleteObjectRaw (const TYPE *object)
 
void deleteObject (bsl::nullptr_t)
 
void deleteObjectRaw (bsl::nullptr_t)
 
- Public Member Functions inherited from bsl::memory_resource
 memory_resource () BSLS_KEYWORD_DEFAULT
 Create this object. Has no effect other than to begin its lifetime.
 
 memory_resource (const memory_resource &) BSLS_KEYWORD_DEFAULT
 
virtual ~memory_resource ()
 Destroy this object. Has no effect other than to end its lifetime.
 
memory_resourceoperator= (const memory_resource &) BSLS_KEYWORD_DEFAULT
 Return a modifiable reference to this object.
 
BSLS_ANNOTATION_NODISCARD void * allocate (size_t bytes, size_t alignment=k_MAX_ALIGN)
 
void deallocate (void *p, size_t bytes, size_t alignment=k_MAX_ALIGN)
 
bool is_equal (const memory_resource &other) const BSLS_KEYWORD_NOEXCEPT
 

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
 

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 bdlma_sequentialallocator

Constructor & Destructor Documentation

◆ SequentialAllocator() [1/13]

bdlma::SequentialAllocator::SequentialAllocator ( bslma::Allocator basicAllocator = 0)
inlineexplicit

◆ SequentialAllocator() [2/13]

bdlma::SequentialAllocator::SequentialAllocator ( bsls::BlockGrowth::Strategy  growthStrategy,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

◆ SequentialAllocator() [3/13]

bdlma::SequentialAllocator::SequentialAllocator ( bsls::Alignment::Strategy  alignmentStrategy,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

◆ SequentialAllocator() [4/13]

bdlma::SequentialAllocator::SequentialAllocator ( bsls::BlockGrowth::Strategy  growthStrategy,
bsls::Alignment::Strategy  alignmentStrategy,
bslma::Allocator basicAllocator = 0 
)
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.

◆ SequentialAllocator() [5/13]

bdlma::SequentialAllocator::SequentialAllocator ( int  initialSize)
inlineexplicit

◆ SequentialAllocator() [6/13]

bdlma::SequentialAllocator::SequentialAllocator ( bsls::Types::size_type  initialSize,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

◆ SequentialAllocator() [7/13]

bdlma::SequentialAllocator::SequentialAllocator ( bsls::Types::size_type  initialSize,
bsls::BlockGrowth::Strategy  growthStrategy,
bslma::Allocator basicAllocator = 0 
)
inline

◆ SequentialAllocator() [8/13]

bdlma::SequentialAllocator::SequentialAllocator ( bsls::Types::size_type  initialSize,
bsls::Alignment::Strategy  alignmentStrategy,
bslma::Allocator basicAllocator = 0 
)
inline

◆ SequentialAllocator() [9/13]

bdlma::SequentialAllocator::SequentialAllocator ( bsls::Types::size_type  initialSize,
bsls::BlockGrowth::Strategy  growthStrategy,
bsls::Alignment::Strategy  alignmentStrategy,
bslma::Allocator basicAllocator = 0 
)
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.

◆ SequentialAllocator() [10/13]

bdlma::SequentialAllocator::SequentialAllocator ( bsls::Types::size_type  initialSize,
bsls::Types::size_type  maxBufferSize,
bslma::Allocator basicAllocator = 0 
)
inline

◆ SequentialAllocator() [11/13]

bdlma::SequentialAllocator::SequentialAllocator ( bsls::Types::size_type  initialSize,
bsls::Types::size_type  maxBufferSize,
bsls::BlockGrowth::Strategy  growthStrategy,
bslma::Allocator basicAllocator = 0 
)
inline

◆ SequentialAllocator() [12/13]

bdlma::SequentialAllocator::SequentialAllocator ( bsls::Types::size_type  initialSize,
bsls::Types::size_type  maxBufferSize,
bsls::Alignment::Strategy  alignmentStrategy,
bslma::Allocator basicAllocator = 0 
)
inline

◆ SequentialAllocator() [13/13]

bdlma::SequentialAllocator::SequentialAllocator ( bsls::Types::size_type  initialSize,
bsls::Types::size_type  maxBufferSize,
bsls::BlockGrowth::Strategy  growthStrategy,
bsls::Alignment::Strategy  alignmentStrategy,
bslma::Allocator basicAllocator = 0 
)
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.

◆ ~SequentialAllocator()

bdlma::SequentialAllocator::~SequentialAllocator ( )

Destroy this sequential allocator. All memory allocated from this allocator is released.

Member Function Documentation

◆ allocate()

void * bdlma::SequentialAllocator::allocate ( bsls::Types::size_type  size)
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.

◆ allocateAndExpand()

void * bdlma::SequentialAllocator::allocateAndExpand ( bsls::Types::size_type size)
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.

◆ deallocate()

void bdlma::SequentialAllocator::deallocate ( void *  address)
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.

◆ release()

void bdlma::SequentialAllocator::release ( )
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.

◆ reserveCapacity()

void bdlma::SequentialAllocator::reserveCapacity ( bsls::Types::size_type  numBytes)
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.

◆ rewind()

void bdlma::SequentialAllocator::rewind ( )
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.

◆ truncate()

bsls::Types::size_type bdlma::SequentialAllocator::truncate ( void *  address,
bsls::Types::size_type  originalSize,
bsls::Types::size_type  newSize 
)
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.


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