BDE 4.14.0 Production release
|
#include <bslma_sequentialpool.h>
Public Member Functions | |
SequentialPool (Allocator *basicAllocator=0) | |
SequentialPool (BufferAllocator::AlignmentStrategy strategy, Allocator *basicAllocator=0) | |
SequentialPool (int initialSize, Allocator *basicAllocator=0) | |
SequentialPool (int initialSize, BufferAllocator::AlignmentStrategy strategy, Allocator *basicAllocator=0) | |
SequentialPool (char *buffer, int bufferSize, Allocator *basicAllocator=0) | |
SequentialPool (char *buffer, int bufferSize, BufferAllocator::AlignmentStrategy strategy, Allocator *basicAllocator=0) | |
SequentialPool (int initialSize, int maxBufferSize, Allocator *basicAllocator=0) | |
SequentialPool (int initialSize, int maxBufferSize, BufferAllocator::AlignmentStrategy strategy, Allocator *basicAllocator=0) | |
SequentialPool (char *buffer, int bufferSize, int maxBufferSize, Allocator *basicAllocator=0) | |
SequentialPool (char *buffer, int bufferSize, int maxBufferSize, BufferAllocator::AlignmentStrategy strategy, Allocator *basicAllocator=0) | |
~SequentialPool () | |
void * | allocate (int size) |
void * | allocateAndExpand (int *size) |
void * | allocateAndExpand (int *size, int maxNumBytes) |
template<class TYPE > | |
void | deleteObject (const TYPE *object) |
template<class TYPE > | |
void | deleteObjectRaw (const TYPE *object) |
int | expand (void *address, int originalNumBytes) |
int | expand (void *address, int originalNumBytes, int maxNumBytes) |
void | release () |
Release all memory currently allocated through this pool. | |
void | reserveCapacity (int numBytes) |
int | truncate (void *address, int originalNumBytes, int newNumBytes) |
This class implements a memory pool that dispenses arbitrarily-sized blocks of memory from an internal buffer or an optionally user-supplied buffer. If an allocation request exceeds the remaining free memory space in the current buffer, the pool either replenishes its buffer with new memory to satisfy the request, or returns a separate memory block, depending on whether the request size exceeds an optionally specified maximum buffer size. By default, buffer growth is not capped. The release
method releases all memory allocated through this pool, as does the destructor. Note, however, that individual allocated blocks of memory cannot be individually deallocated.
|
explicit |
|
explicit |
|
explicit |
bslma::SequentialPool::SequentialPool | ( | int | initialSize, |
BufferAllocator::AlignmentStrategy | strategy, | ||
Allocator * | basicAllocator = 0 |
||
) |
Create a sequential pool 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::SequentialPool::SequentialPool | ( | char * | buffer, |
int | bufferSize, | ||
Allocator * | basicAllocator = 0 |
||
) |
bslma::SequentialPool::SequentialPool | ( | char * | buffer, |
int | bufferSize, | ||
BufferAllocator::AlignmentStrategy | strategy, | ||
Allocator * | basicAllocator = 0 |
||
) |
Create a sequential pool 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::SequentialPool::SequentialPool | ( | int | initialSize, |
int | maxBufferSize, | ||
Allocator * | basicAllocator = 0 |
||
) |
bslma::SequentialPool::SequentialPool | ( | int | initialSize, |
int | maxBufferSize, | ||
BufferAllocator::AlignmentStrategy | strategy, | ||
Allocator * | basicAllocator = 0 |
||
) |
Create a sequential pool 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::SequentialPool::SequentialPool | ( | char * | buffer, |
int | bufferSize, | ||
int | maxBufferSize, | ||
Allocator * | basicAllocator = 0 |
||
) |
bslma::SequentialPool::SequentialPool | ( | char * | buffer, |
int | bufferSize, | ||
int | maxBufferSize, | ||
BufferAllocator::AlignmentStrategy | strategy, | ||
Allocator * | basicAllocator = 0 |
||
) |
Create a sequential pool 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
.
|
inline |
Destroy this object and release all memory currently allocated through this pool.
void * bslma::SequentialPool::allocate | ( | int | size | ) |
Return memory of the specified size
. If size
is 0, no memory is allocated and 0 is returned. The behavior is undefined unless 0 <= size
.
void * bslma::SequentialPool::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::SequentialPool::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
.
|
inline |
Destroy the specified object
. Note that this method is exactly the same as the deleteObjectRaw
method since no deallocation is involved. This method exists purely for consistency across pools.
|
inline |
Destroy the specified object
. Note that the memory is not deallocated because there is no deallocate
method in a bslma_sequentialpool .
int bslma::SequentialPool::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::SequentialPool::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
.
void bslma::SequentialPool::release | ( | ) |
void bslma::SequentialPool::reserveCapacity | ( | int | numBytes | ) |
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::SequentialPool::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
.