stdio line-streaming revisited

Walter Bright newshound1 at digitalmars.com
Wed Mar 28 21:46:31 PDT 2007


kris wrote:
> On Win32, the difference is very much larger. As noted before, several 
> times faster.

I suspect that much of the slowness difference is from using C's fputs, 
along with the need to append a 0 to use fputs.

std.stdio.readln will also automatically convert to char[] if the stream 
is in wide character mode (as will all the phobos stdio functions). This 
test is inlined and fast under Windows, but is a function call under 
Linux which will hurt performance significantly.

> If you mean something that you've written, that could presumeably be 
> rectified by adding the isatty() test Walter had mentioned before. That 
> has not been added to tango.io since (a) it would likely make programs 
> behave differently depending on whether they were redirected or not. 
> It's not yet clear whether that is an appropriate specialization, as 
> default behaviour, and (b) there has been no ticket issued for it
> 
> Again, please submit a ticket so we don't forget about that detail. We'd 
> be interested to hear if folk think the "isatty() test" should be 
> default behaviour, or would perhaps lead to corner-case issues instead

Using isatty() to switch between line and block buffered I/O access is 
routine when using C's stdio, and in fact is relied upon in DMC's 
internal implementation of buffering. It's been this way for 25 years, 
every C stdio implementation I've heard of uses it, and I've never heard 
a complaint about it.



More information about the Digitalmars-d mailing list