Next topic |
Ada Home Page |
Index
Structured binary files
Text files have no structure.
They are just a stream of characters. Programmers must give special meaning
to certain characters to recognise the pages and lines in text files.
Structured binary files have a definite structure:
- elements are all the same type (usually records)
- elements are stored in the same binary representation as they have in
computer memory
- no LINE oriented operations
Since structured files are not stored as a sequence of characters:
- cannot read/write them with text editors
- I/O performed using special I/O packages (not TEXT_IO)
- read/write by program only
Choosing to use structured files
when?
- program designed for specific data
- program executed often with same data
- scratch files
- temporary storage during execution
why?
- read/write entire element at once
- efficient data representation
Types of structured files
There are two forms of structured files. The difference is in how their
elements may be accessed:
Comparisons
Direct files vs sequential files:
- Direct files have the overhead of working out file sizes and locations
within the file. Sequential files do not.
- Access to an individual element can be immediate with direct files. With
a sequential file, all previous elements must be read before a given
element is reached.
Which to use?
- Sequential files are appropriate when you want to read most or all of the
records in the file every time you run your program.
- Direct access files are appropriate when only a few records
will be processed.
Structured files vs arrays:
- In holding multiple elements of data, each of the same type,
structured files have something in common with arrays.
- The comparisons are summarised in the following tables:
| Structured file | Array |
Access speed | Slow (Secondary storage) |
Fast (Primary memory) |
Size limit | Unlimited | Bounded |
Life time | Permanent | Transient |
| Access method |
Array | Direct or sequential |
Sequential file | Sequential |
Direct access file | Direct or sequential |
Next topic |
Ada Home Page |
Index
c-lokan@adfa.oz.au / 23 Feb 96