Random Access Files:
In data files discussed above, the data (or records) was written into the file in an order, i.e. in a sequence. It was accessed from the tile in the same order in which it was written. This method of accessing data is called sequential and the files are called sequential access files.
Accessing a data item directly is called direct access or random access. The files in which data is accessed randomly are called random access files. In these files, data or records can he read from or updated at any place into the file. This process of accessing records is very fast.
Various techniques are used to access records in random access files. The most commonly used technique is that:
- All records are stored in the file with fixed record length.
- The records are stored in an order one after the other.
- The fixed length of each record is used to access any specified record. In this technique, the records can be accessed sequentially as well as randomly.
When a specific record is accessed randomly, the member function of the object calculates exact location of the specified record by multiplying the record number with the record size. The control jumps directly to the required record without accessing other records. This technique to access records is very fast.
Table below shows storage technique of records on the storage media. In this example, each record has a fixed length of 50 bytes.
|
0 |
50 |
100 |
150 |
200 |
250 |
|
Record 1 |
Record 2 |
Record 3 |
Record 4 |
Record 5 |
… |
Following operations can he performed in these files:
- Inserting new record at any location.
- Deleting any record from the file.
- Updating any record into the file.
To read or write a record in a random access file, the position of the record in the file is specified. To specify the position of the record in the file, two member functions are used.
comment closed