Please enable JavaScript to view this site.

A-Shell Consolidated Reference

Navigation: Subroutines > MIAMEX

MX_NOBUF, MX_FLUSHBUF

Scroll Prev Top Next More

Reorganized April 2024

xcall MIAMEX, MX_NOBUF, channel

xcall MIAMEX, MX_FLUSHBUF, channel

(Unix only) MX_NOBUF (MIAMEX 87) will disable the normal stream buffering on output streams (i.e. files open for output, and the console itself, aka stdout).

MX_FLUSHBUF (MIAMEX 88) flushes (or "unbuffers") the data, which has been buffered but not yet written to the specified file channel.

Parameters

channel (Num)  [in]

is the file channel to disable buffering on. The file must be open for output (or append). For the terminal device, use file channel 0 (which is automatically opened for you at the start of each program).

Comments

By default, Unix systems buffer output streams to minimize the amount of system overhead involved in writing to them. For files, the buffer size may be several K. For the terminal or console, the buffering is generally limited to a single line.

In general this buffering is highly desirable, but there may be cases where it is annoying. One situation occurs when you are treating a physical port as a file, in order to control device connected to that port. In such a case, you may write out a small command to the file/port thinking that the device will see it immediately, but due to the buffering, it would not. A more typical situation involves writing some kind of status information (aka "life signs") to the screen during a lengthy process. Unless each update of the status information ended with a line terminator, it would simply be buffered, with the result that instead of seeing dots or percentage completion indicators steadily appear on the screen, there is a delay, and then it all appears at once. One (but not the only) solution to these problems would be to just disable buffering on the file channel in question.

An alternate approach is to force the buffer to be flushed on demand. For terminal devices, you can do this with Tab(-1,254), or simply by ending a PRINT statement without a semicolon. For file devices, you can use Function 88.

This buffering issue does not affect data files that are open for random I/O, ISAM, etc.