Vectored I/O & Memory-Mapping
This topic covers two aspects of Advanced File I/O: (1) Scatter/gather I/O [= Vectored I/O] and (2) Memory-mapped I/O.
Scatter/Gather I/O, also known as Vectored I/O, is a method in which a single syscall reads or writes a vector (= array) of buffers from a single data file stream.
The advantages of Scatter/Gather I/O over linear I/O (= regular I/O as we've covered so far) are:
- More natural coding pattern: intuitive for naturally segmented data, e.g., multiple lines or strings of text.
- Efficiency: a single vectored I/O operation is used instead of multiple linear I/O calls.
- Performance: the OS can optimize the I/O operations done via Scatter/Gather I/O, making this method faster than multiple linear I/O calls.
- Locked: there is no risk of interleaving (= messing up) I/O from another process or thread.