VCE IT Lecture Notes by Mark Kelly, McKinnon Secondary College
Serial, sequential and random access
|
||||||||||||
|
2011 -SD KK4.1.03-methods of organising files to suit particular software needs, including serial, sequential and random access |
||||||||||||
SERIAL FILEA serial file consists of sets of data of the same record type (but usually the records are of different lengths) that is stored in the same order in which the records were created. They have not been sorted. Examples are transaction files (in which sales are added to the file as they occur) or shopping lists, in which items are added to the end of the list as you think of them. A search of a serial file is performed by sequential comparison of the query with identifiers of all stored items. CSV (comma-separated values) is a common serial/sequential file format in which text fields are delimited by commas. Sample serial file -SALES.DAT"Smith", "Fred", "2", "Blue widgets", "$12.22", "23/8/2010" |
||||||||||||
SEQUENTIAL FILEA sequential file is one in which the differently-sized records are stored in sorted order by one or more key fields. A class list is an example of a non-computerised sequential file sorted on surname, then first name. Searching is a little easier in a sequential file because at least you can tell that you have gone past the item you are seeking. Sample sequential file -SALESSORTED.DAT (sorted by name)"Adams", "Alexander", "9", "Green grommets", "$45.33", "25/8/2010"
|
||||||||||||
PROs and CONs of SERIAL and SEQUENTIAL FILESIn both serial and sequential files, to read item N, all items from 1 to N-1 must be read first. It is impossible to jump directly to a particular record. This makes serial/sequential files simple and fast to create, but slow and awkward to use later. Think of a library where books are stacked in the order in which they are bought, and to find a particular book, you start at the first one and keep searching until you eventually find the one you want. Unlike random access files in which you can instantly access any record without having to traverse all the records between where you are and where you want to be. Think of serial & sequential files as cassette tape: if you want to listen to song 13, you have to fast-forward or rewind from your current position to the start of song 13. Compare it to a CD where you can lift the read head and drop it exactly where it needs to read next. |
||||||||||||
RANDOM ACCESSRandom access files have a predictable, strict structure that lets you directly seek and go to the start of a desired record. This strucure is only possible because each record has a fixed length. A random file may be define as follows:
|
||||||||||||
PROs and CONs RANDOM ACCESS FILESWhile random files are faster to search and access, they can both waste storage space and potentially cut off data. e.g. if a name field in a random file's record is defined as being 15 characters long, the name "JONES" would have 10 bytes excess. On the other hand, the famous name
would have his name cut off after "Gambolputty de ", leading to inaccurate data. When design random file records, considerable thought needs to go into choosing the maximum lengths of fields to prevent problems later. |
||||||||||||
A Random File Example (written in VB6)
|
||||||||||||
Back to the IT Lecture Notes index
Back to the last page you visited
Created 13 Sep 2010
Last changed: September 13, 2010 1:25 PM
VCE IT Lecture notes copyright © Mark Kelly 2001-