This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Linux vs. libio


Per Bothner wrote:

> One can write a C++ wrapper class (say stdiobuf) that implements the
> C++ functionality, but uses the C stdio buffers.  The problem is that
> this is slow, since you have to call handle_slow_case on every
> character.  You can force that by setting read_pointer == read_limit
> (for those streams that are aliased to stdio).  Alternatively, you can
> make sure to use the same value of read_pointer for C FILEs and C++
> filebufs.  However, then either you get extra overhead (indirection)
> or you have to merge the data structures for C and C++.

From http://www.sgi.com/Technology/STL/standard_library.html:

Another place where we've got system dependent code is syncing with
stdio. The C++ standard requires that there be a mode in which
iostreams and stdio are synchronized (the C++ standard is imprecise
about just what synchronization means, but, after talking to the
people who wrote that part of the standard, it's clear that it means a
very close coupling), and it requires that synchronized mode be the
default. We could have satisfied this requirement by implementing
things in terms of putc and getc, but that would have been horribly
inefficient. Instead we did something uglier, but more efficient: we
directly manipulate the pointers inside a FILE object. We've
encapsulated knowledge of struct FILE into the header
<stl_stdio_file.h>, which defines a few inline functions for this
manipulation. Again, this header has to be modified for every OS that
we target. This has not proven to be a serious problem in practice,
since most stdio implementations appear to be very similar to each
other.

Which is what I was trying to get at.  By directly maniplulating FILE
one avoids the extra overhead.

-- 
Kevin Atkinson
kevinatk@home.com
http://metalab.unc.edu/kevina/

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]