BloombergLP::bslma::BufferAllocator::allocateFromBuffer

Allocate a memory block of the specified size from buffer with the specified alignment.

Synopsis

Declared in <bslma_bufferallocator.h>

static
void*
allocateFromBuffer(
    int* cursor,
    char* buffer,
    size_type bufSize,
    size_type size,
    int alignment);

Description

Allocate a memory block of the specified size from the specified buffer at the specified cursor position using the specified alignment. Return the address of the allocated memory block if buffer contains enough available memory, and null otherwise. The cursor is set to the index of the next available byte in buffer after the allocation. If size is 0, do not allocate memory and return zero. The behavior is undefined unless 0 <= bufSize, 0 <= size, `0 < alignment <= bsls::AlignmentUtil::BSLS_MAX_ALIGNMENT`, and alignment is an integral power of 2.

Return Value

address of the allocated block, or null if insufficient space

Parameters

NameDescription
cursorIndex of the next available byte in buffer (in/out).
bufferMemory buffer from which to allocate.
bufSizeSize (in bytes) of buffer.
sizeNumber of bytes to allocate.
alignmentAlignment (in bytes) for the allocated block.