How many random / sequential access per fread / fwrite?

前端 未结 5 1206
孤街浪徒
孤街浪徒 2021-01-21 03:53

I have the following question regarding C file I/O.

At a physical level (harddrive), is it valid to assume that every fread(n_blocks, size, length,FILE fp)

5条回答
  •  北海茫月
    2021-01-21 04:35

    No it's not. You can't even assume that an fread will trigger physical I/O. Your OS has the possibility to do a lot of stuff with I/O requests, including caching the results, reordering and coalescing (or splitting) reads (and even sometimes writes).

    If there is a lot of I/O going on, you can't count on getting sequential reads either, depending on what size buffer you (and possibly the I/O stream library) use. Some operating systems provide ways to "hint" that you will be reading sequentially on a file descriptor (or mmaped region) which could help.

提交回复
热议问题