|
Boost Users : |
Subject: Re: [Boost-users] IOStream: Determine number of bytes written to array sink
From: Peter Klotz (Peter.Klotz_at_[hidden])
Date: 2018-11-23 11:11:31
Hi Steven
> -----Original Message-----
> From: Boost-users [mailto:boost-users-bounces_at_[hidden]] On Behalf
> Of Steven Watanabe via Boost-users
...
> std::streamsize optimal_buffer_size() const { return 0; }
>
> template<typename Sink>
> std::streamsize write(Sink& snk, const char* s, std::streamsize n)
> {
> std::streamsize result = iostreams::write(snk, s, n);
> chars_ += result;
> return result;
> }
Thanks for the tip! I had hoped there was some kind of well hidden buffer pointer to do some pointer arithmetic.
One problem I stumbled into with the counter filter:
If optimal_buffer_size() returns 0, write() is called with 1 byte buffers. In my case this increased the program runtime from 8 seconds to 4 minutes.
Returning a larger value solved this issue for my use case.
Regards, Peter.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net