Access Methods in File Management
Files are used to store data. The information present in the file can be accessed by various methods. Thus, the way of retrieving data from a file is known as access method. Different systems use different access methods. The various access methods used are:
- Sequential access
- Direct access
- Indexed access
It is the simplest and most commonly used access method. In sequential access, information in the file is accessed in the order it is stored in the file i.e. one record after the other. Thus, the various records are read sequentially one after the other in an order, starting a the beginning to the end of the file. The various records cannot be read randomly out of order i.e. we cannot skip any record in between.
For example, reading of 34th record followed by 5th record and then 1st record is not possible in sequential access.
In this way, the file pointer is automatically advanced in the read operation which tracks the I/O location. record In case of write operation, the new content is appended to the end of file. Sequential file can be reset to the starting of the file. In some system, it is also possible to shift n records of some integer value backward or forward. Sequential access is convenient when the storage medium is magnetic tape, rather than disk.
Advantages of Sequential Access Method
- It is one of the simplest method of file access and easy to implement.
- There is no need for any storage space identification.
- It uses disk and memory efficiently.
- It also allows data to be stored on many types of media, in a device independent manner.
- Errors in the files remain localized.
- It is also economical and easier to organize and maintain.
Disadvantages of Sequential access method
- Searching a record is a time consuming affair as it allows only sequential access. To search a record at nth location entire file needs to be processed.
- New records can only be added to the end of a file.
- It requires the transactions to be sorted in a particular sequence before processing.
- There is high data redundancy.
- It is not possible to handle the random enquiries.
In direct access method it is possible to access the records of a file in any order (i.e. out of order). For example, if we are reading block 13, we can read block 46 after this and then block 20.
The various records can be read or write randomly. There is no restriction on the order of reading or writing for a direct access file. ta this way the records can be accessed by key, rather than by position. This method is also known as relative access method and is typically used in systems implementing disks rather than magnetic tapes. In direct access method, the various records or blocks of a file are numbered for reference purpose. In order to perform read or write operation, we specify block number where read or write operation is to be performed.
Thus, an instruction read n will read block number n. Thus a user provides a block number to an operating system. This number is known as relative block number. It is an index to starting of the file. So, in a file, the first relative block number is 0, the next relative block number is 1 and so on.
Direct access method is important for many applications, for example, database systems. In a banking application, a customer may want to look up his current balance. This can be done by locating this customer’s record using his account number as a key, rather than sequentially reading the records for thousand of the customers before this customer’s record is located and read.
Advantages of direct or random access method
- It results in faster access of desired record. As a result retrieval process is not so time consuming as in direct access.
- It does not require records to be sorted before processing.
- It allows faster updating of several files.
- It also allows the random record deletion and insertion.
- It is best suited for online transaction processing system like online reservation system.
Disadvantages of direct or random access method
- This method requires backup facility as records are directly updated.
- It requires expensive direct access storage devices such as hard disk to store records.
- If is less efficient as compared to sequential file organization in terms of usage of storage space.
- Data may be accidentally erased or overwritten unless special precautions are taken.
- It is not possible to access such a file sequentially.
- Only one key is used.
In this method, an index is created for the file. This index contains pointer for various blocks of a file, just like an index in the back of a book. If we want to find a record of a file, first the index is searched and then the pointer f index is used to access that file. In this way, a required record is found. When the size of a file is large, its index itself becomes too large. In such a further an index is created for the index file. The primary index or main index contains the pointers to secondary index files, which would point to the actual data items. T another index is created for situation index.
Advantage of indexed access method
- This method allows records to be processed both sequentially and randomly in a efficient manner.
- Accessing of records is faster and less time consuming but requires index table to be properly organized.
Disadvantage of indexed access method
- It requires a lot of storage space because of the presence of index.
- As compared to other access method, indexed access is less efficient in terms of usage of storage space
- The indexed files have to be reorganized from time to time to get rid of deleted records and improve performance that gets gradually decreased with addition of new records.
- It is also expensive as it requires special software and extra storage for index.