[#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&hyphen;specified sizes) from an external buffer whose address and size are optionally supplied at construction&period; 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&period; Note that in no event will the buffer manager attempt to deallocate the external buffer&period;

== Synopsis

Declared in `&lt;bdlma&lowbar;buffermanager&period;h&gt;`

[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[`&#126;BufferManager`] [.small]#[destructor]#
| Destroy this buffer manager&period;
| xref:BloombergLP/bdlma/BufferManager/alignmentStrategy.adoc[`alignmentStrategy`] 
| Return the alignment strategy passed to this object at construction&period;
| 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&period; 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&period;
| 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&period; The behavior is undefined unless the allocation request does not exceed the remaining free memory space in the external buffer, `0 &lt; size`, and this object is currently managing a buffer&period;
| 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&period;
| 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&period;
| xref:BloombergLP/bdlma/BufferManager/calculateAlignmentOffsetFromSize.adoc[`calculateAlignmentOffsetFromSize`] 
| Return the minimum non&hyphen;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`&period; Note that if `0 &equals;&equals; size` and natural alignment was provided at construction, the result of this method is identical to the result for `0 &equals;&equals; size` and maximal alignment&period;
| xref:BloombergLP/bdlma/BufferManager/deleteObject.adoc[`deleteObject`] 
| Destroy the specified `object`&period; 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&period;
| xref:BloombergLP/bdlma/BufferManager/deleteObjectRaw.adoc[`deleteObjectRaw`] 
| Destroy the specified `object`&period; Note that memory associated with `object` is not deallocated because there is no `deallocate` method in `BufferManager`&period;
| 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&period; Return the amount of memory available at `address` after expanding, or `size` if the memory at `address` cannot be expanded&period; 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&period; 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`&period;
| 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&period; The behavior is undefined unless `0 &lt; size`, and this object is currently managing a buffer&period;
| xref:BloombergLP/bdlma/BufferManager/release.adoc[`release`] 
| Release all memory currently allocated through this buffer manager&period; After this call, the external buffer managed by this object is retained&period; Subsequent allocations will allocate memory from the beginning of the external buffer (if any)&period;
| 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)&semi; return the address of the previously held buffer, or 0 if this object currently manages no buffer&period; The replaced buffer (if any) is removed from the management of this object with no effect on the outstanding allocated memory blocks&period; Subsequent allocations will allocate memory from the beginning of the new external buffer&period; The behavior is undefined unless `0 &lt; newBufferSize` and `newBuffer` has at least `newBufferSize` bytes&period;
| 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&period; The currently managed buffer (if any) is removed from the management of this object with no effect on the outstanding allocated memory blocks&period;
| 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)&period; Return `newSize` after truncating, or `originalSize` if the memory at `address` cannot be truncated&period; 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&period; 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 &lt;&equals; originalSize`, `0 &lt;&equals; newSize`, and `release` was not called after allocating the memory at `address`&period;
|===



[.small]#Created with https://www.mrdocs.com[MrDocs]#
