BloombergLP::bdlma::BufferImpUtil::allocateFromBuffer

Allocate a memory block from a buffer using the specified alignment strategy.

Synopsis

Declared in <bdlma_bufferimputil.h>

static
void*
allocateFromBuffer(
    bsls::Types::IntPtr* cursor,
    char* buffer,
    bsls::Types::size_type bufferSize,
    bsls::Types::size_type size,
    bsls::Alignment::Strategy strategy);

Description

Allocate a memory block of the specified size (in bytes) from the specified buffer having the specified bufferSize (in bytes) at the specified cursor position, using the specified alignment strategy. Return the address of the allocated memory block if buffer contains sufficient available memory, and 0 otherwise. The cursor is set to the first byte position immediately after the allocated memory if there is sufficient memory, and not modified otherwise. The behavior is undefined unless 0 < size, 0 <= *cursor, and *cursor <= bufferSize.

Return Value

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

Parameters

NameDescription
cursorbyte offset into buffer at which to allocate
buffermemory buffer from which to allocate
bufferSizesize in bytes of buffer
sizesize in bytes of the memory block to allocate
strategyalignment strategy used to align the allocated block