O'Reilly logo

Advanced Mac OS X Programming: The Big Nerd Ranch Guide by Mark Dalrymple

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required