[#BloombergLP-bdlma-BufferImpUtil-allocateMaximallyAlignedFromBuffer]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdlma.adoc[bdlma]::xref:BloombergLP/bdlma/BufferImpUtil.adoc[BufferImpUtil]::allocateMaximallyAlignedFromBuffer
:relfileprefix: ../../../
:mrdocs:

Allocate a maximally&hyphen;aligned memory block from a buffer&period;

== Synopsis

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

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
static
void*
allocateMaximallyAlignedFromBuffer(
    xref:BloombergLP/bsls/Types/IntPtr.adoc[bsls::Types::IntPtr]* cursor,
    char* buffer,
    xref:BloombergLP/bsls/Types/size_type.adoc[bsls::Types::size&lowbar;type] bufferSize,
    xref:BloombergLP/bsls/Types/size_type.adoc[bsls::Types::size&lowbar;type] size);
----

== Description

Allocate a maximally&hyphen;aligned memory block of the specified `size` (in bytes) from the specified `buffer` having the specified `bufferSize` (in bytes) at the specified `cursor` position&period; Return the address of the allocated memory block if `buffer` contains sufficient available memory, and 0 otherwise&period; The `cursor` is set to the first byte position immediately after the allocated memory if there is sufficient memory, and not modified otherwise&period; The behavior is undefined unless `0 &lt; size`, `0 &lt;&equals; &ast;cursor`, and `&ast;cursor &lt;&equals; bufferSize`&period;

== Return Value

address of the allocated memory block if `buffer` contains sufficient available memory, and 0 otherwise

== Parameters

[cols="1,4"]
|===
| Name| Description
| *cursor*
| byte offset into `buffer` at which to allocate
| *buffer*
| memory buffer from which to allocate
| *bufferSize*
| size in bytes of `buffer`
| *size*
| size in bytes of the memory block to allocate
|===


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