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

#include <bslma_sequentialallocator.h>

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

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)
 
 ~SequentialAllocator () BSLS_KEYWORD_OVERRIDE
 Destroy this sequential allocator and release all associated memory.
 
void * allocate (size_type numBytes) BSLS_KEYWORD_OVERRIDE
 
void * allocateAndExpand (int *size)
 
void * allocateAndExpand (int *size, int maxNumBytes)
 
void deallocate (void *address) BSLS_KEYWORD_OVERRIDE
 This method has no effect for this allocator.
 
int expand (void *address, int originalNumBytes)
 
int expand (void *address, int originalNumBytes, int maxNumBytes)
 
void release () BSLS_KEYWORD_OVERRIDE
 Release all memory currently allocated through this allocator.
 
virtual void reserveCapacity (int numBytes)
 
int truncate (void *address, int originalNumBytes, int newNumBytes)
 
- 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 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 bslma_sequentialallocator

Constructor & Destructor Documentation

◆ SequentialAllocator() [1/10]

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

◆ SequentialAllocator() [2/10]

bslma::SequentialAllocator::SequentialAllocator ( BufferAllocator::AlignmentStrategy  strategy,
Allocator basicAllocator = 0 
)
inlineexplicit

◆ SequentialAllocator() [3/10]

bslma::SequentialAllocator::SequentialAllocator ( int  initialSize,
Allocator basicAllocator = 0 
)
inlineexplicit

◆ SequentialAllocator() [4/10]

bslma::SequentialAllocator::SequentialAllocator ( int  initialSize,
BufferAllocator::AlignmentStrategy  strategy,
Allocator basicAllocator = 0 
)
inline

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.

◆ SequentialAllocator() [5/10]

bslma::SequentialAllocator::SequentialAllocator ( char *  buffer,
int  bufferSize,
Allocator basicAllocator = 0 
)
inline

◆ SequentialAllocator() [6/10]

bslma::SequentialAllocator::SequentialAllocator ( char *  buffer,
int  bufferSize,
BufferAllocator::AlignmentStrategy  strategy,
Allocator basicAllocator = 0 
)
inline

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.

◆ SequentialAllocator() [7/10]

bslma::SequentialAllocator::SequentialAllocator ( int  initialSize,
int  maxBufferSize,
Allocator basicAllocator = 0 
)
inline

◆ SequentialAllocator() [8/10]

bslma::SequentialAllocator::SequentialAllocator ( int  initialSize,
int  maxBufferSize,
BufferAllocator::AlignmentStrategy  strategy,
Allocator basicAllocator = 0 
)
inline

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.

◆ SequentialAllocator() [9/10]

bslma::SequentialAllocator::SequentialAllocator ( char *  buffer,
int  bufferSize,
int  maxBufferSize,
Allocator basicAllocator = 0 
)
inline

◆ SequentialAllocator() [10/10]

bslma::SequentialAllocator::SequentialAllocator ( char *  buffer,
int  bufferSize,
int  maxBufferSize,
BufferAllocator::AlignmentStrategy  strategy,
Allocator basicAllocator = 0 
)
inline

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.

◆ ~SequentialAllocator()

bslma::SequentialAllocator::~SequentialAllocator ( )

Member Function Documentation

◆ allocate()

void * bslma::SequentialAllocator::allocate ( size_type  numBytes)
inlinevirtual

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.

◆ allocateAndExpand() [1/2]

void * bslma::SequentialAllocator::allocateAndExpand ( int *  size)
inline

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.

◆ allocateAndExpand() [2/2]

void * bslma::SequentialAllocator::allocateAndExpand ( int *  size,
int  maxNumBytes 
)
inline

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.

◆ deallocate()

void bslma::SequentialAllocator::deallocate ( void *  address)
inlinevirtual

Implements bslma::Allocator.

◆ expand() [1/2]

int bslma::SequentialAllocator::expand ( void *  address,
int  originalNumBytes 
)
inline

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.

◆ expand() [2/2]

int bslma::SequentialAllocator::expand ( void *  address,
int  originalNumBytes,
int  maxNumBytes 
)
inline

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.

◆ release()

void bslma::SequentialAllocator::release ( )
inlinevirtual

◆ reserveCapacity()

void bslma::SequentialAllocator::reserveCapacity ( int  numBytes)
inlinevirtual

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.

◆ truncate()

int bslma::SequentialAllocator::truncate ( void *  address,
int  originalNumBytes,
int  newNumBytes 
)
inline

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.


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