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

#include <bdlma_bufferedsequentialallocator.h>

Inheritance diagram for bdlma::BufferedSequentialAllocator:
bdlma::ManagedAllocator bslma::Allocator bsl::memory_resource bdlma::LocalSequentialAllocator< k_BUFFER_SIZE > bdlma::LocalSequentialAllocator< t_SIZE >

Public Member Functions

 BufferedSequentialAllocator (char *buffer, bsls::Types::size_type size, bslma::Allocator *basicAllocator=0)
 
 BufferedSequentialAllocator (char *buffer, bsls::Types::size_type size, bsls::BlockGrowth::Strategy growthStrategy, bslma::Allocator *basicAllocator=0)
 
 BufferedSequentialAllocator (char *buffer, bsls::Types::size_type size, bsls::Alignment::Strategy alignmentStrategy, bslma::Allocator *basicAllocator=0)
 
 BufferedSequentialAllocator (char *buffer, bsls::Types::size_type size, bsls::BlockGrowth::Strategy growthStrategy, bsls::Alignment::Strategy alignmentStrategy, bslma::Allocator *basicAllocator=0)
 
 BufferedSequentialAllocator (char *buffer, bsls::Types::size_type size, bsls::Types::size_type maxBufferSize, bslma::Allocator *basicAllocator=0)
 
 BufferedSequentialAllocator (char *buffer, bsls::Types::size_type size, bsls::Types::size_type maxBufferSize, bsls::BlockGrowth::Strategy growthStrategy, bslma::Allocator *basicAllocator=0)
 
 BufferedSequentialAllocator (char *buffer, bsls::Types::size_type size, bsls::Types::size_type maxBufferSize, bsls::Alignment::Strategy alignmentStrategy, bslma::Allocator *basicAllocator=0)
 
 BufferedSequentialAllocator (char *buffer, bsls::Types::size_type size, bsls::Types::size_type maxBufferSize, bsls::BlockGrowth::Strategy growthStrategy, bsls::Alignment::Strategy alignmentStrategy, bslma::Allocator *basicAllocator=0)
 
 ~BufferedSequentialAllocator () BSLS_KEYWORD_OVERRIDE
 
void * allocate (size_type size) BSLS_KEYWORD_OVERRIDE
 
void deallocate (void *address) BSLS_KEYWORD_OVERRIDE
 
void release () BSLS_KEYWORD_OVERRIDE
 
virtual void rewind ()
 
bslma::Allocatorallocator () const
 Return the allocator passed at construction.
 
- 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 an external buffer whose address and size (in bytes) are supplied at construction. If an allocation request exceeds the remaining free memory space in the external buffer, memory will be supplied by an (optional) allocator also supplied at construction; if no allocator is supplied, the currently installed default allocator is used. This class is exception neutral: If memory cannot be allocated, the behavior is defined by the (optional) allocator supplied at construction. Note that in no case will the buffered sequential allocator attempt to deallocate the external buffer.

See bdlma_bufferedsequentialallocator

Constructor & Destructor Documentation

◆ BufferedSequentialAllocator() [1/8]

bdlma::BufferedSequentialAllocator::BufferedSequentialAllocator ( char *  buffer,
bsls::Types::size_type  size,
bslma::Allocator basicAllocator = 0 
)
inline

◆ BufferedSequentialAllocator() [2/8]

bdlma::BufferedSequentialAllocator::BufferedSequentialAllocator ( char *  buffer,
bsls::Types::size_type  size,
bsls::BlockGrowth::Strategy  growthStrategy,
bslma::Allocator basicAllocator = 0 
)
inline

◆ BufferedSequentialAllocator() [3/8]

bdlma::BufferedSequentialAllocator::BufferedSequentialAllocator ( char *  buffer,
bsls::Types::size_type  size,
bsls::Alignment::Strategy  alignmentStrategy,
bslma::Allocator basicAllocator = 0 
)
inline

◆ BufferedSequentialAllocator() [4/8]

bdlma::BufferedSequentialAllocator::BufferedSequentialAllocator ( char *  buffer,
bsls::Types::size_type  size,
bsls::BlockGrowth::Strategy  growthStrategy,
bsls::Alignment::Strategy  alignmentStrategy,
bslma::Allocator basicAllocator = 0 
)
inline

Create a buffered sequential allocator for allocating memory blocks from the specified external buffer having the specified size (in bytes). Optionally specify a growthStrategy used to control buffer growth. If a growthStrategy is not specified, geometric growth is used. Optionally specify an alignmentStrategy used to align allocated memory blocks. If an alignmentStrategy is not specified, natural alignment is used. Optionally specify a basicAllocator used to supply memory should the capacity of buffer be exhausted. If basicAllocator is 0, the currently installed default allocator is used. The behavior is undefined unless 0 < size, and buffer has at least size bytes. Note that, due to alignment effects, it is possible that not all size bytes of memory in buffer can be used for allocation. Also 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 size.

◆ BufferedSequentialAllocator() [5/8]

bdlma::BufferedSequentialAllocator::BufferedSequentialAllocator ( char *  buffer,
bsls::Types::size_type  size,
bsls::Types::size_type  maxBufferSize,
bslma::Allocator basicAllocator = 0 
)
inline

◆ BufferedSequentialAllocator() [6/8]

bdlma::BufferedSequentialAllocator::BufferedSequentialAllocator ( char *  buffer,
bsls::Types::size_type  size,
bsls::Types::size_type  maxBufferSize,
bsls::BlockGrowth::Strategy  growthStrategy,
bslma::Allocator basicAllocator = 0 
)
inline

◆ BufferedSequentialAllocator() [7/8]

bdlma::BufferedSequentialAllocator::BufferedSequentialAllocator ( char *  buffer,
bsls::Types::size_type  size,
bsls::Types::size_type  maxBufferSize,
bsls::Alignment::Strategy  alignmentStrategy,
bslma::Allocator basicAllocator = 0 
)
inline

◆ BufferedSequentialAllocator() [8/8]

bdlma::BufferedSequentialAllocator::BufferedSequentialAllocator ( char *  buffer,
bsls::Types::size_type  size,
bsls::Types::size_type  maxBufferSize,
bsls::BlockGrowth::Strategy  growthStrategy,
bsls::Alignment::Strategy  alignmentStrategy,
bslma::Allocator basicAllocator = 0 
)
inline

Create a buffered sequential allocator for allocating memory blocks from the specified external buffer having the specified size (in bytes), or from an internal buffer (after the external buffer is exhausted) where the buffer growth is limited to the specified maxBufferSize (in bytes). Optionally specify a growthStrategy used to control buffer growth. If a growthStrategy is not specified, geometric growth is used. Optionally specify an alignmentStrategy used to align allocated memory blocks. If an alignmentStrategy is not specified, natural alignment is used. Optionally specify a basicAllocator used to supply memory should the capacity of buffer be exhausted. If basicAllocator is 0, the currently installed default allocator is used. The behavior is undefined unless 0 < size, size <= maxBufferSize, and buffer has at least size bytes. Note that, due to alignment effects, it is possible that not all size bytes of memory in buffer can be used for allocation. Also note that when constant growth is used, the size of the internal buffers will always be the same as size.

◆ ~BufferedSequentialAllocator()

bdlma::BufferedSequentialAllocator::~BufferedSequentialAllocator ( )

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

Member Function Documentation

◆ allocate()

void * bdlma::BufferedSequentialAllocator::allocate ( 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 external buffer supplied at construction, use memory obtained from the allocator supplied at construction.

Implements bslma::Allocator.

◆ allocator()

bslma::Allocator * bdlma::BufferedSequentialAllocator::allocator ( ) const
inline

◆ deallocate()

void bdlma::BufferedSequentialAllocator::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. The effect of using address after this call is undefined.

Implements bslma::Allocator.

◆ release()

void bdlma::BufferedSequentialAllocator::release ( )
inlinevirtual

Release all memory allocated through this allocator and return to the underlying allocator all memory except the external buffer supplied at construction. The allocator is reset to its default-constructed state, making the memory from the entire external buffer supplied at construction available for subsequent allocations, 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.

◆ rewind()

void bdlma::BufferedSequentialAllocator::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.


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