User Tools

Site Tools


flushing_20file_20buffers

Flushing file buffers

by Richard Russell, June 2010

When you write to a sequential data file using PRINT# or BPUT# the data is buffered by BBC BASIC before being output to Windows (typically for storage on disk). This is done for reasons of performance, because transferring data in blocks is more efficient than transferring it one byte at a time. A similar process occurs when you are reading from a file.

These buffering operations normally happen transparently, and you don't need to be aware of them. However there are a couple of circumstances in which the existence of the buffers can matter to your BBC BASIC program:

  1. If you are mixing BASIC file-access statements (e.g. PRINT#, BPUT#) with Windows API calls (e.g. SYS “WriteFile”) which access the same file, it is important that the buffer be flushed in between using one variety of access and the other.
  2. If the file you are creating is shared between two processes (e.g. one program writing to the file and another program reading from the file) it is necessary to flush the buffers to ensure that all the data written by one program can be read by the other program.


In both cases flushing BBC BASIC's file buffer is simply a case of issuing the following statement:

        PTR#chan% = PTR#chan%

where chan% is the channel number returned by OPENIN, OPENOUT or OPENUP.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
flushing_20file_20buffers.txt · Last modified: 2024/01/05 00:22 by 127.0.0.1