Li Chen
Li Chen

Reputation: 5280

Why system call like WRITE(2) doesn't provide buffer to increase speed?

Compared to functions like printf(), system call write() is usually slower because it has no buffer. But why not provide a built-in buffer in write(). OSes' speed is important, isn't it?

I am not familiar with operating system, it quite confuses me.

Upvotes: 0

Views: 72

Answers (1)

Stephen C
Stephen C

Reputation: 719606

Because they are the low level calls to the operating system on which the higher level (buffered) methods like fread, fwrite, fflush and so on are implemented.

OSes' speed is important, isn't it?

Yes it is. But it is assumed that application is going to make write() calls efficiently. If it needs buffering, it should use fwrite.


So if read is not buffered and buffering is more efficient, why don't they hide it?

Because buffering is not always more efficient. In fact, for some use-cases a buffered stream does more copying than using write directly. For bulk I/O operations this extra copy leads to slower I/O.

Upvotes: 1

Related Questions