[ASIO] boos::asio::basic_streambuf does not accept user defined size during construction. Still defaults to 128
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 9000 for receiving an encapsulated packet on socket). The initial allocation (buffer_.resize is done with 128. But when we call *buf.prepare(9000)*, 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 for the same. For time being, I modified the library code to the following to ensure it does not break the default argument, but accepts user defined value. Alternatively, I can change buffer delta to be of larger value, but don't want to end up with a large buffer for no reason. if (max_size_ == std::numeric_limitsstd::size_t::max()) pend = (std::minstd::size_t)(max_size_, buffer_delta); else pend = std::maxstd::size_t(max_size_, buffer_delta); Regards Aniket. -------------------- original code ---------------- enum { buffer_delta = 128 }; /// 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_limitsstd::size_t::max)(), const Allocator& allocator = Allocator()) : max_size_(maximum_size), buffer_(allocator) { *std::size_t pend = (std::minstd::size_t)(max_size_, buffer_delta);* *buffer_.resize((std::maxstd::size_t)(pend, 1));* setg(&buffer_[0], &buffer_[0], &buffer_[0]); setp(&buffer_[0], &buffer_[0] + pend); }
participants (1)
-
Aniket Pugaonkar