News:

This week IPhone 15 Pro winner is karn
You can be too a winner! Become the top poster of the week and win valuable prizes.  More details are You are not allowed to view links. Register or Login 

Main Menu

C++ Tips: IO - slow standard c++ I/O

Started by ben2ong2, October 06, 2006, 11:27:19 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ben2ong2

(Newsgroup: comp.lang.c++.moderated, 4 May 2000)

[ This is part a discussion about why the C++ I/O facilities sometimes
  are slow (more in another tip). -adc ]

[snip]

AUSTERN: Matt Austern <austern@sgi.com>

The C++ iostreams library can be synchronized with the C stdio
library.  The C++ standard is slightly vague about what "synchronized"
means, but, from talking to the people who wrote that part of the
standard, the clear intent was that we were talking about a very tight
coupling.  For example, you should be able to read a character with
getchar(), then put it back with std::cin.rdbuf()->sputbackc(), and
then read it again either from stdin or from cin.

This tight coupling comes at a cost.  Now notice I said that the C++
iostreams library "can be" synchronized.  What this means is that
there are two modes for C++ I/O through the standard narrow stream
objects: a slow synchronized mode, and a fast unsynchronized mode.
In some implementations the speed difference between the two modes is
very large.

The C++ standard requires the iostreams library to use the slow
synchronized mode by default.  If you care about performance, and if
you don't plan to do a lot of mixing of stdio and iostreams, then
you should put the line
    std::sync_with_stdio(false);
in your program before doing any I/O.


_______________________________________________
cpptips mailing list
You are not allowed to view links. Register or Login

You are not allowed to view links. Register or Login
You are not allowed to view links. Register or Login