bug-apl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-apl] Patch: cout buffer control


From: Chris Moller
Subject: Re: [Bug-apl] Patch: cout buffer control
Date: Fri, 22 Aug 2014 11:24:50 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.7.0

This may be a result of buffer sizes.  I don't know enough about C++ to know how to do it, but maybe if you reduce the buffer size, it will reduce the latency.


On 08/22/14 11:08, David Lamkins wrote:
I agree: cout << endl should flush the buffer. It does when stdout is a tty. For some reason, the buffering becomes much more aggressive when the stdout is a pipe.


On Fri, Aug 22, 2014 at 6:14 AM, Juergen Sauermann <address@hidden> wrote:
Hi David,

thanks, included in SVN 443.

This is interesting because I normally use something like out << endl which should have flushed the buffer.
On the other hand is somewhat special because it prints a prompt but no endl so that the user enters her input
on the same line.

I have added a few cout << flush for ⎕/⍞ so maybe the patch isn't needed anymore (I guess unbuffered output
is slightly slower than buffered output).

/// Jürgen


On 08/22/2014 05:11 AM, David Lamkins wrote:
Oops. Here's the same patch, but inquiring about the correct file descriptor.

(It'll work either way in some cases...)


On Thu, Aug 21, 2014 at 8:06 PM, David Lamkins <address@hidden> wrote:
I've been puzzled by the interaction between GNU APL and aplwrap, in which ⎕ and ⍞ output doesn't appear until APL prompts for input. This behavior is bad for the case where the program tries to emit periodic progress messages during long computations.

It turns out that the C++ std lib is responsible for this behavior. While cerr is unbuffered, cout holds onto buffered content for as long as possible. (Apparently it only does this when stdout is not a terminal, as running the same test in a shell window does not exhibit the aggressive buffering behavior.)

I learned that cout's buffering behavior can be be changed using the call:

std::cout.setf(std::ios::unitbuf);

This can be called sometime before running the main APL loop, and will cause cout's buffer to be flushed at each <<, the same as cerr.

The attached patch (GNU APL SVN 441) runs the 'unitbuf' code only in the case that stdin is not a tty.





--




--


reply via email to

[Prev in Thread] Current Thread [Next in Thread]