C++ iostreams provides control over whether C++ streams must be synchronized with C streams via std::ios_base::sync_with_stdio()
. Turning off stream synchronization allows the standard library implementation to use independent unsynchronized buffers for C++ streams and C streams to potentially improve performance.
Why was it considered important to leave a door open for implementers to use separate independent sets of io buffers for C and C++ streams? I don't see how this could potentially improve performance compared to one set of io buffers. Allowing the standard library one set of io buffers at the program level can reduce the number of usually expensive calls to the underlying OS io facilities, but what could be the advantage of two sets of io buffers?
Is there a technical reason that separate buffers for C and C++ streams could benefit performance or is the design just a historical artifact?
Does it somehow have to do with the committee wanting C++ implementors to be able to implement the C++ standard library by building upon their existing C standard library implementations?
I'm looking for more than "the standard says so".
If OS characteristics are necessary to explain the rationale, answers are welcome to use as examples the io facilities provided by a real OS or to explain a hypothetical, but reasonable, OS.
Edit: To clarify, the question is not why synchronizing streams can harm performance. The question is why the C++ standard was designed with the assumption that there may be two sets of io buffers at all and why leaving that possibility open is useful for implementers. std::ios_base::sync_with_stdio()
just happens to be the consequence of this assumption.