2009年1月14日 星期三

What's the difference between fopen / open , fwrite / write etc...

open() is a system call, this system call will different based on each kind of OS.
fopen() is C library API, fopen() will call different API(ex:open()) in different OS.


open() operated directly on the device, while fopen() does not.

When you open a file with "fopen", a tempoary buffer will be created.
Use open(), no buffer is created.

If you want to write a portable program, please use fopen().

PS:一般用fopen打開普通檔案,用open打開設備檔案

直接使用低階system call,有效率不佳的問題:
1.執行system call,Linux必須將你的程式碼切換到核心程式碼,隨後在返回。
2.一般來說,使用低階system call,硬體對於讀寫得資料區塊大小會有限制,例如:寫入磁帶機,通常會有區塊打小的限制,通常為10K,如果寫入非10K的倍數,磁帶機就會存取下一個10K區塊。

沒有留言: