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 ...

Get Advanced Mac OS X Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.