Forum Navigation
Cout and flushing behavior
Posted: 01/30/08 20:55:35I wanted to get other people's opinion on this. In the current implementation of Cout, the the system checks to see if the output is to a console. If it is, every newline flushes the buffer. If it is not, the buffer is flushed when it is full.
I see the benefit of having this behavior, but the issue I have is that when I create a pipeline of applications, the D ones tend to be very bursty, which isn't what I want. For example, I have an application that takes a long time to run, and so every 10 percent through the process, I print the percentage completed. However, if I redirect this through another application, no percentage is printed until the application is 100% finished.
Now I understand that it is possible to configure Cout to always flush even if the file descriptor is not a console, but I don't always remember to do this, and by the time I figure out what is wrong, I've already built a system with the incorrect value. I'm assuming the current behavior is based on the expectation that the user most of the time wants the non-flushing behavior when redirected and flushing behavior when not redirected.
What I have found is that my desire for a program to behave the same way whether it is redirected or simply run on the console far overrides my desire to have Cout be more efficient in its printing (actually the desire for the latter is slightly above zero).
Anyone else have this opinion (or the opposite)?
-Steve