|
BDE 4.14.0 Production release
|
#include <bdlma_buffermanager.h>
This class implements a buffer manager that dispenses heterogeneous blocks of memory (of varying, user-specified sizes) from an external buffer whose address and size are optionally supplied at construction. If an allocation request exceeds the remaining free memory space in the external buffer, the allocation request returns 0 if allocate is used, or results in undefined behavior if allocateRaw is used. Note that in no event will the buffer manager attempt to deallocate the external buffer.
|
inlineexplicit |
Create a buffer manager for allocating memory blocks. Optionally specify an alignment strategy used to align allocated memory blocks. If strategy is not specified, natural alignment is used. A default constructed buffer manager is unable to allocate any memory until an external buffer is provided by calling the replaceBuffer method.
|
inline |
Create a buffer manager for allocating memory blocks from the specified external buffer having the specified bufferSize (in bytes). Optionally specify an alignment strategy used to align allocated memory blocks. If strategy is not specified, natural alignment is used. The behavior is undefined unless 0 < bufferSize and buffer has at least bufferSize bytes.
|
inline |
|
inline |
Return the alignment strategy passed to this object at construction.
|
inline |
Return the address of a contiguous block of memory of the specified size (in bytes) on success, according to the alignment strategy specified at construction. If size is 0 or the allocation request exceeds the remaining free memory space in the external buffer, no memory is allocated and 0 is returned.
|
inline |
Return the address of a contiguous block of memory of the specified size (in bytes) according to the alignment strategy specified at construction. The behavior is undefined unless the allocation request does not exceed the remaining free memory space in the external buffer, 0 < size, and this object is currently managing a buffer.
|
inline |
Return an address providing modifiable access to the buffer currently managed by this object, or 0 if this object currently manages no buffer.
|
inline |
Return the size (in bytes) of the buffer currently managed by this object, or 0 if this object currently manages no buffer.
|
inline |
Return the minimum non-negative integer that, when added to the numerical value of the specified address, yields the alignment as per the alignmentStrategy provided at construction for an allocation of the specified size. Note that if 0 == size and natural alignment was provided at construction, the result of this method is identical to the result for 0 == size and maximal alignment.
|
inline |
Destroy the specified object. Note that this method has the same effect as the deleteObjectRaw method (since no deallocation is involved), and exists for consistency with a pool interface.
|
inline |
Destroy the specified object. Note that memory associated with object is not deallocated because there is no deallocate method in BufferManager.
| bsls::Types::size_type bdlma::BufferManager::expand | ( | void * | address, |
| bsls::Types::size_type | size | ||
| ) |
Increase the amount of memory allocated at the specified address from the original size (in bytes) to also include the maximum amount remaining in the buffer. Return the amount of memory available at address after expanding, or size if the memory at address cannot be expanded. This method can only expand the memory block returned by the most recent allocate or allocateRaw request from this buffer manager, and otherwise has no effect. The behavior is undefined unless the memory at address was originally allocated by this buffer manager, the size of the memory at address is size, and release was not called after allocating the memory at address.
|
inline |
Return true if there is sufficient memory space in the buffer to allocate a contiguous memory block of the specified size (in bytes) after taking the alignment strategy into consideration, and false otherwise. The behavior is undefined unless 0 < size, and this object is currently managing a buffer.
|
inline |
Release all memory currently allocated through this buffer manager. After this call, the external buffer managed by this object is retained. Subsequent allocations will allocate memory from the beginning of the external buffer (if any).
|
inline |
Replace the buffer currently managed by this object with the specified newBuffer of the specified newBufferSize (in bytes); return the address of the previously held buffer, or 0 if this object currently manages no buffer. The replaced buffer (if any) is removed from the management of this object with no effect on the outstanding allocated memory blocks. Subsequent allocations will allocate memory from the beginning of the new external buffer. The behavior is undefined unless 0 < newBufferSize and newBuffer has at least newBufferSize bytes.
|
inline |
Reset this buffer manager to its default constructed state, except retain the alignment strategy in effect at the time of construction. The currently managed buffer (if any) is removed from the management of this object with no effect on the outstanding allocated memory blocks.
| bsls::Types::size_type bdlma::BufferManager::truncate | ( | void * | address, |
| bsls::Types::size_type | originalSize, | ||
| bsls::Types::size_type | newSize | ||
| ) |
Reduce the amount of memory allocated at the specified address of the specified originalSize (in bytes) to the specified newSize (in bytes). Return newSize after truncating, or originalSize if the memory at address cannot be truncated. This method can only truncate the memory block returned by the most recent allocate or allocateRaw request from this object, and otherwise has no effect. The behavior is undefined unless the memory at address was originally allocated by this buffer manager, the size of the memory at address is originalSize, newSize <= originalSize, 0 <= newSize, and release was not called after allocating the memory at address.