Accessing storage devices means reading or writing to a storage device. Modern storage devices like rotating disks, SSDs, and flash drives allow both random and sequential storage. Let's explore the differences between random and sequential access.
Sequential access, as the name suggests, is when data is read or written in a sequentially ordered manner or sequence.
In sequential writing to storage, the instruction to write data provides an address only at the beginning. Writing starts at the provided address and continues to the following addresses until the data is written storage.
Sequential reading from the storage is also similar. The instruction only provides an address once where the reading commences and continues in the following addresses.
The image below demonstrates sequential access.
In the image above, the array of blocks is storage hardware, with each block representing a unit of storage. The text inside each block is its address. Arrows represent the movement of the hardware's
So, for our example, the first read or write took place at address 001
. Then, the pointer moved to address 002
(arrow with number 1
), after which the next read or write happened at address 002
. Then, the pointer moved to address 003
(arrow with number 2
), and so on. The main characteristic of sequential access is that after it has moved to the address where reading or writing will start, the pointer only moves to point to the next address.
A classic example of sequential access is a tape drive. It consists of a magnetic tape and head—its version of a mechanism that allows reading and writing.
Random access is when data is read or written in an unordered manner.
In random writing to storage, the instruction to write data only provides an address with every data object that needs to be written. Every data object is written at its respective address.
Random reading from storage is also similar. The instructions for random reads provide addresses from where data needs to be read.
The image below demonstrates random access.
Like before, the array of blocks is a storage medium and the arrows represent the movement of the pointer. The difference here is that the pointer does not always move to point to the next address. It can move to point to any of the addresses in the medium.
So, for our example, the first read or write took place at address 001
. Then, the pointer moved to address 003
(arrow with number 1
), after which the next read or write happened at address 003
. Then, the pointer moved to address 006
(arrow with number 2
), and so on.
Sequential access is generally much faster than random access because the pointer in sequential access only has to move to one location and keep reading from that address. It only moves to the adjacent address when it has to move. With random access, the pointer has to move to a new location every time it starts a read or write, which takes time.