libstdc++/3269: Inefficient stream output, one 'write' call per character

Carlo Wood carlo@alinoe.com
Tue Jun 26 17:25:00 GMT 2001


On Tue, Jun 26, 2001 at 02:10:23PM -0700, Benjamin Kosnik wrote:
> 
> It was changed because of sync_with_stdio(true) problems. If you look at 
> the test for this stuff, you can see that syncd' io has to be "in sync" 
> on a per-byte basis. Sorry, those are the rules.
> 
> The way around this is to disengage the C/C++ io requirement, which is 
> why sync_with_stdio(false) is in the standard. 
> 
> Seems pretty straightforward, although perhaps non-intuitive. This should 
> be an acceptable cross-platform, standards-compliant solution.
> 
> -benjamin

What he meant is that instead of doing a system call (write) for one
character at a time, you might as well do a single, blocking call to
write(2) when you know a whole string at once.

When streambuf doesn't have a buffer it calls overflow(int c) for each character
seperately, and then indeed we can't do anything but writing it character by
character.

Perhaps a solution would therefore be to give streambuf the idea that there is a
huge (fake) buffer so that it will always call xsputn(char const* s, std::streamsize n)
and then do a (series of) blocking call(s) to write(2) there.

-- 
Carlo Wood <carlo@alinoe.com>



More information about the Gcc-bugs mailing list