I/O Statements

Input/Output statements divide into two general categories: sequential access and random access. On the AMOS platform, this distinction exists even at the file level: random files, also known as contiguous files, are actually allocated as single contiguous sets of blocks on the disk, unlike sequential files which are allocated as linked lists of blocks. On the Windows and UNIX platforms, the operating system makes no distinction between the two types of files—all files are allocated as a linked list of blocks—and all files may be accessed using either sequential or random-access methods, determined by the way the file is opened. In practice, any given file is typically accessed by one method or the other, not both, based on the type of data and general purpose of the file.

Sequential Access

• text-oriented, typically

• byte, field, or line-oriented

• variable length fields and lines

• files are opened for input or output, but not both

• no record locking

• the screen is a special sequential file; open for output on channel 0

• the keyboard is a special sequential file; open for input

• serial ports may be accessed as sequential files

• output files may be created by the OPEN statement and grow automatically via PRINT

• the DATA statement pool acts like a sequential input file, internal to the program

• access is by default sequential but can be overridden using MX_FILEPOS.

Random Access

• fixed length records containing a mixture of field types

• ISAM and ISAM-A files are special variants of random access files

• files must be pre-allocated; see ALLOCATE, CREATE

• file expansion typically not automatic, except for ISAM, ISAM-A; see MX_EXPFIL

• file and record locking is available; see LOKSER

• records may be "blocked" into 512 byte blocks; see OPEN for random access statement