Skip to content

Clarify the contract of max_size in DynamicBufferParam #320

Description

@akrzemi1

During discussions it became apparent that member function max_size on types modelling DynamicBufferParam (so this probably also applies to DynamicBuffer) has different meaning than the member function of the same name and signature in STL containers.

In STL containers max_size() means (https://en.cppreference.com/cpp/container/vector/max_size):

The maximum number of elements the container of this type is able to hold due to system or library implementation limitations, i.e. std::distance(begin(), end()) for the largest container.

In Capy, DynamicBuffer defines max_capacity vaguely:

Maximum allowed size. Attempts to grow beyond this throw or fail.

But some algorithms (read_until) inconsistently use it for controlling the number of bytes to be read from the stream, which follows the pattern from ASIO: https://www.boost.org/doc/libs/latest/doc/html/boost_asio/reference/read/overload6.html.

Document clearly what the contract of this operation in DynamicBufferParam is. (It could be an additional semantic requirement relative to DynamicBuffer). If the goal is to control the logic of stream algorithms, change the name of the function so that does not incorrectly imply the semantics of max_size from STL containers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions