[#BloombergLP-bdlma-BufferManager] = xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdlma.adoc[bdlma]::BufferManager :relfileprefix: ../../ :mrdocs: 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. == Synopsis Declared in `<bdlma_buffermanager.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- class BufferManager; ---- == Member Functions [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bdlma/BufferManager/2constructor-0c6.adoc[`BufferManager`] [.small]#[constructor]# | Constructors | xref:BloombergLP/bdlma/BufferManager/2destructor.adoc[`~BufferManager`] [.small]#[destructor]# | Destroy this buffer manager. | xref:BloombergLP/bdlma/BufferManager/alignmentStrategy.adoc[`alignmentStrategy`] | Return the alignment strategy passed to this object at construction. | xref:BloombergLP/bdlma/BufferManager/allocate.adoc[`allocate`] | 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. | xref:BloombergLP/bdlma/BufferManager/allocateRaw.adoc[`allocateRaw`] | 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. | xref:BloombergLP/bdlma/BufferManager/buffer.adoc[`buffer`] | Return an address providing modifiable access to the buffer currently managed by this object, or 0 if this object currently manages no buffer. | xref:BloombergLP/bdlma/BufferManager/bufferSize.adoc[`bufferSize`] | Return the size (in bytes) of the buffer currently managed by this object, or 0 if this object currently manages no buffer. | xref:BloombergLP/bdlma/BufferManager/calculateAlignmentOffsetFromSize.adoc[`calculateAlignmentOffsetFromSize`] | 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. | xref:BloombergLP/bdlma/BufferManager/deleteObject.adoc[`deleteObject`] | 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. | xref:BloombergLP/bdlma/BufferManager/deleteObjectRaw.adoc[`deleteObjectRaw`] | Destroy the specified `object`. Note that memory associated with `object` is not deallocated because there is no `deallocate` method in `BufferManager`. | xref:BloombergLP/bdlma/BufferManager/expand.adoc[`expand`] | 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`. | xref:BloombergLP/bdlma/BufferManager/hasSufficientCapacity.adoc[`hasSufficientCapacity`] | 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. | xref:BloombergLP/bdlma/BufferManager/release.adoc[`release`] | 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). | xref:BloombergLP/bdlma/BufferManager/replaceBuffer.adoc[`replaceBuffer`] | 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. | xref:BloombergLP/bdlma/BufferManager/reset.adoc[`reset`] | 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. | xref:BloombergLP/bdlma/BufferManager/truncate.adoc[`truncate`] | 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`. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#