Page 1 of 1

<write> and <flush>

Posted: Mon Mar 25, 2024 4:24 pm
by aitchon
If I use <write> to write log lines to an output file, is there any buffering of the output before it writes to file? If so, can the size of the buffer be controlled? Would flush be used if there is data in the buffer?

Re: <write> and <flush>

Posted: Mon Mar 25, 2024 4:35 pm
by John
<write> does buffer, and the buffer size can't be controlled. You could use either <flush> or </write> to flush the data. For log files it's generally best to generate the log line and then write it out as a single item, e.g.

Code: Select all

<write append $logfile>$-logline</write>

Re: <write> and <flush>

Posted: Mon Mar 25, 2024 4:55 pm
by aitchon
What is the current default buffer size?

Re: <write> and <flush>

Posted: Tue Mar 26, 2024 11:51 am
by John
Is there a particular concern? In general the most predictable method would be to generate the logline, e.g. with <capture>, including the newline, and output to the log in a single <write>...</write> using either $-logline or <fmt "%s" $logline> if an older texis. That will attempt to write the entire line in one shot. Generally each Vortex statement inside the <write> will be written individually. If the logline is longer than the OS can handle it might be split into multiple writes, but that's beyond our control.

Re: <write> and <flush>

Posted: Tue Mar 26, 2024 12:56 pm
by Kai
<write> uses a dynamically-sized buffer. It buffers the entire contents of a single print-to-output Vortex statement, then writes that output in a single write() system call to the <write> file. Literal Vortex text is buffered, up to a line I think. There may be exceptions to these rules but I can't find any offhand.