<write> and <flush>

Post Reply
aitchon
Posts: 118
Joined: Mon Jan 22, 2007 10:30 am

<write> and <flush>

Post 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?
User avatar
John
Site Admin
Posts: 2597
Joined: Mon Apr 24, 2000 3:18 pm
Location: Cleveland, OH
Contact:

Re: <write> and <flush>

Post 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>
John Turnbull
Thunderstone Software
aitchon
Posts: 118
Joined: Mon Jan 22, 2007 10:30 am

Re: <write> and <flush>

Post by aitchon »

What is the current default buffer size?
User avatar
John
Site Admin
Posts: 2597
Joined: Mon Apr 24, 2000 3:18 pm
Location: Cleveland, OH
Contact:

Re: <write> and <flush>

Post 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.
John Turnbull
Thunderstone Software
User avatar
Kai
Site Admin
Posts: 1272
Joined: Tue Apr 25, 2000 1:27 pm

Re: <write> and <flush>

Post 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.
Post Reply