Nascom Newsletter |
Volume 3 · Number 3 · August 1983 |
Page 33 of 37 |
---|
end-of-record marker delimits data items it is not essential that the records are of fixed length. Therefore it is impossible to replace an item in the middle of a file directly – there is no certainty where the record concerned begins,or whether the replacement will exactly fit in the space. Editing of these files can therefore be laborious, as is access to any point in the file. The method which would need to be used to insert an item would be to read each record from an input file and copy it to a new output file. When the point at which the new record is to be inserted is reached the new record would be output, and then the remainder of the file would be read and copied record by record into the new file. The old file could then be deleted and the new one re-named.
Sequential files are quite convenient when you wish to read all the contents of a file into memory and carry out the manipulation of the data in memory. When you have finished processing the data in memory the entire data can be written to a sequential file. Thus in handling data which can be loaded into memory this is a convenient method to use, since operating on the data in memory is inevitably quicker than any method which requires repeated disc access to obtain individual data items. Small data files and index files can conveniently be treated in this way.
A random file can be read/written directly at any point. In NAS-DOS the positions in a file are measured in disc sectors (of 256 bytes) from the start of the file. In its simplest, and most common form, each record will be up to 255 bytes long and will occupy one sector. You can go to any sector directly by specifying its relative sector number in the file prior to the read or write operation. This is done by a DOKE to location 3365 of the relative sector number, starting at 0 for the first sector, eg
120 DOKE 3365,10
Since you have direct access in this way to any point in a file it is very simple to amend a specific record simply by rewriting the appropriate sector of data on disc. You can if necessary arrange your own ‘housekeeping’ routines to pack two sets of data into a sector, or to use 2 sectors to store each set of data. For example in the latter case you would access the 10’th item of the data by starting to read at relative sector 18 of the file (the first item is in sectors 0 and 1, the second in 2 and 3 etc).
The problem with a random file is knowing where to store a new item of data, and more importantly where to find a data item. Most records stored on disc will have the most important item in the record at the beginning. The individual items of data in a record are usually known as fields, and the first of these, or the one by which each record is usually referenced (eg in searchesS) is the key field. One method of inserting a new record into a random file would be to store the records in alphabetical order by their key field. This has two major drawbacks – firstly to store an item we would have to move all records up the file to create the space for the new entry. The
Page 33 of 37 |
---|