boost::capy::circular_dynamic_buffer

A fixed‐capacity circular buffer satisfying DynamicBuffer.

Synopsis

class circular_dynamic_buffer;

Description

This class implements a circular ( ring ) buffer with fixed capacity determined at construction. Unlike linear buffers, data can wrap around from the end to the beginning, enabling efficient FIFO operations without memory copies.

Buffer sequences returned from data and prepare may contain up to two elements to represent wrapped regions.

Example

char storage[1024];
circular_dynamic_buffer cb( storage, sizeof( storage ) );

// Write data
auto mb = cb.prepare( 100 );
std::memcpy( mb.data(), "hello", 5 );
cb.commit( 5 );

// Read data
auto cb_data = cb.data();
// process cb_data...
cb.consume( 5 );

Thread Safety

Distinct objects: Safe. Shared objects: Unsafe.

Types

Name

Description

const_buffers_type

The ConstBufferSequence type for readable bytes.

is_dynamic_buffer_adapter

Indicates this is a DynamicBuffer adapter over external storage.

mutable_buffers_type

The MutableBufferSequence type for writable bytes.

Member Functions

Name

Description

circular_dynamic_buffer [constructor]

Constructors

operator=

Copy assignment.

capacity

Return the number of writable bytes without reallocation.

commit

Move bytes from the output to the input sequence.

consume

Remove bytes from the beginning of the input sequence.

data

Return a buffer sequence representing the readable bytes.

max_size

Return the maximum number of bytes the buffer can hold.

prepare

Return a buffer sequence for writing.

size

Return the number of readable bytes.

See Also

flat_dynamic_buffer, string_dynamic_buffer

Created with MrDocs