There are several files that will be stored in computer memory. When an application needs a file, the operating system should search in the computer memory and has to access the required files. There are several ways the operating system can access the information in the files called File Access Methods. The file access methods provide operations like reading from or writing to a file stored in the computer memory. The various file access methods are,
- Sequential Access Method
- Direct Access Method
- Indexed Access Method
- Indexed Sequential Access Method.
Sequential Access Method :
Among all the access methods, it is considered the simplest method. As the name itself suggest it is the sequential (or series) processing of information present in a file. Due to its simplicity most of the compilers, editors, etc., use this method.
Processing is carried out with the use of two operations namely, read and write. Read operation is responsible for reading the next portion of the file and after a successful read of the record, the pointer proceeds automatically to the next record which tracks the I/O location. Write operation is responsible for writing at the end of the file and shifts the pointer towards the end of the newly added record.
In this type of access, while processing the records sequentially, some of the records can be skipped in both directions (either forward or backward) and can also be reset or rewind to the head of the file (beginning). The above figure shows a tape model of sequential access of files.
Advantages of Sequential Access Method :
- This method of file access is easy to implement.
- It provides fast access to the next record using lexicographic order.
Disadvantages of Sequential Access Method :
- This type of file access method is slow if the file record to be accessed next is not present next to the current record.
- Inserting a new record may require moving a large proportion of the file.
Direct Access Method :
This access method is also called real-time access where the records can be read irrespective of their sequence. This means they can be accessed as a file that is accessed from a disk where each record carries a sequence number. For example, block 40 can be accessed first followed by block 10 and then block 30, and so on. This eliminates the need for sequential read or write operations.
A major example of this type of file access is the database where the corresponding block of the query is accessed directly for instant response. This type of access saves a lot of time when a large amount of data is present. In such cases, hash functions and index methods are used to search for a particular block.
The read next and write next operations of sequential access are modified to read n and write n, where ‘n’ is the block number. A more promising approach is to use direct access to map the position of the file and sequential access for performing read next operation in that block.
This can be done by using relative block numbers which are nothing but index related to the access of blocks. For example, relative block numbers 0, 1, 2, … can be allocated to block numbers 72, 1423, 20, etc. This approach is adopted by some of the operating systems while others use either sequential or direct access.
Advantages of Direct Access Method :
- The files can be immediately accessed decreasing the average access time.
- In the direct access method, in order to access a block, there is no need of traversing all the blocks present before it.
Indexed Access Method :
This method is typically an advancement in the direct access method which is the consideration of index. A particular record is accessed by browsing through the index and the file is accessed directly with the use of a pointers or addresses present in the index as shown below.
To understand the concept consider a book store where the database contains a 12-digit ISBN and a four-digit product price. If the disk can carry 2048 (2kb) of bytes per block then 128 records of 16 bytes (12 for ISBN and 4 for price) can be stored in a single block. This results in a file carrying 128000 records to be reduced to 1000 blocks to be considered in the index each entry carrying 10 digits. To find the price of a book binary search can be performed over the index with which the block carrying that book can be identified.
A drawback of this method is, it is considered ineffective in the case of a larger database with very large files which results in making the index too large.
Indexed Sequential Access Method :
To overcome the drawback associated with indexed access, this method is used where an index of an index is created. Primary index points to the secondary index and the secondary index points to the actual data items as shown below.
An example of such a method is ISAM (Indexed-Sequential Access Method) of IBM which carries two types of indexes. They are a master index and secondary index.
Master index carries pointers to the secondary index whereas, the secondary carries blocks that point directly to the disk blocks. Two binary searches are performed to access a data item. The first one is performed on a master index and the second one on the secondary index. This type of method is a two direct access read method.