in reply to Re: print inside a loop
in thread print inside a loop
Often...
More specifically, when the buffering mode is set to "line-buffered" — which is the default with interactive things like terminals.
In general, and to summarize, there are three buffering modes:
In block-buffered mode, flushing doesn't happen before the respective buffer, e.g. 4k bytes size, has filled up.
For example (block-buffered):
$ strace -ewrite perl -E 'say "X"x99 for 1..100' >/dev/null write(1, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"..., 4096) = 4096 write(1, "XXX\nXXXXXXXXXXXXXXXXXXXXXXXXXXXX"..., 4096) = 4096 write(1, "XXXXXXX\nXXXXXXXXXXXXXXXXXXXXXXXX"..., 1808) = 1808
Without the redirect of stdout, i.e. when it's connected to the terminal, you'd see 100 write system calls à 100 bytes... (line-buffered)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: print inside a loop
by bart (Canon) on Feb 22, 2011 at 13:06 UTC | |
by Eliya (Vicar) on Feb 22, 2011 at 13:28 UTC |