Boost logo

Boost :

From: Jerker Öhman (jerker.ohman_at_[hidden])
Date: 2007-01-16 04:58:33

I posted this to boost.user but didn't get any reply so I will try here

The problem (as far as I can tell) is that a buffered iostreams::stream
dumps it's internal buffers every time you call seek or tell, even if
you seek to the current position.

You end up in this function.

template<typename T, typename Tr, typename Alloc, typename Mode>
typename indirect_streambuf<T, Tr, Alloc, Mode>::pos_type
indirect_streambuf<T, Tr, Alloc, Mode>::seek_impl
       (stream_offset off, BOOST_IOS::seekdir way, BOOST_IOS::openmode
       if (pptr() != 0)
           this->BOOST_IOSTREAMS_PUBSYNC(); // sync() confuses VisualAge 6.
       if (way == BOOST_IOS::cur && gptr())
           off -= static_cast<off_type>(egptr() - gptr());
       setg(0, 0, 0);
       setp(0, 0);
       return obj().seek(off, way, which, next_);

I am no expert in iostreams but I think that the naive idea would be to
check if the buffer already contains the position we are searching for
and if so, adjust the buffers accordingly (at least if the stream is
binary). With the current implementation you can't really use buffered
streams if you seek a lot in them (which, perhaps is the reason you want
to use buffered streams in the first place).

Boost list run by bdawes at, gregod at, cpdaniel at, john at