Boost logo

Boost :

From: Aniket Pugaonkar (aniket.pugaonkar_at_[hidden])
Date: 2022-12-05 15:35:52


Hello,

I was checking the implementation of boost streambuf and noticed that
buffer_delta value is defaulted to 128, which results in the capacity of
the container to 128 bytes by default,
and based on that, there is no way to change it even if we provide max size
as some custom number (say 1500 for receiving a packet on socket).
The initial allocation (buffer_.resize is done with 128. But when we call
*buf.prepare(1500)*, it again results in resize(n) operation (through
reserve(n) function call.

Is there any other way to change this other than modifying the constructor
in our codebase to provide a user defined value of buffer_delta
Not sure if this needs to be enhanced. the maximum_size argument seems to
be of no use in this case...

Kindly advise.

Regards
Aniket.

  /// Construct a basic_streambuf object.
  /**
   * Constructs a streambuf with the specified maximum size. The initial
size
   * of the streambuf's input sequence is 0.
   */
  explicit basic_streambuf(
      std::size_t maximum_size = (std::numeric_limits<std::size_t>::max)(),
      const Allocator& allocator = Allocator())
    : max_size_(maximum_size),
      buffer_(allocator)
  {
    *std::size_t pend = (std::min<std::size_t>)(max_size_, buffer_delta);*
    *buffer_.resize((std::max<std::size_t>)(pend, 1));*
    setg(&buffer_[0], &buffer_[0], &buffer_[0]);
    setp(&buffer_[0], &buffer_[0] + pend);
  }

-- 
Thanks and regards,
Aniket Pugaonkar

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk