How is fseek() implemented in the filesystem?

后端 未结 6 1598
[愿得一人]
[愿得一人] 2020-12-30 02:13

This is not a pure programming question, however it impacts the performance of programs using fseek(), hence it is important to know how it works. A little disclaimer so tha

6条回答
  •  春和景丽
    2020-12-30 02:30

    One observation I have made about fseek on Solaris, is that each call to it resets the read buffer of the FILE. The next read will then always read a full block (8K by default). So if you have a lot of random access with small reads it's a good idea to do it unbuffered (setvbuf with NULL buffer) or even use direct syscalls (lseek+read or even better pread which is only 1 syscall instead of 2). I suppose this behaviour will be similar on other OS.

提交回复
热议问题