Buffered I/O vs. Unbuffered I/O
With buffered I/O, there is a lot of data copying happening:
program structures –> FILE buffer –> kernel buffer –> disk.
With unbuffered I/O, the copy to the FILE buffer is avoided, and with scatter/gather I/O, the kernel might be able to avoid a copy into its own buffers.
Since read() and write() are not buffered (except for a disk block or two in the kernel data structures), they can be slow when dealing with lots of smaller reads and writes. Buffered I/O would be a win here.
When doing big reads and writes, say dozens of K of image data, there is a win to using plain read() and write() calls to avoid the buffering step in between.
Fundamentally, everything boils down to the file descriptor. Even FILEs have ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access