How many random / sequential access per fread / fwrite?

前端 未结 5 1239
孤街浪徒
孤街浪徒 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:40

    As many explained, caching (perhaps at several levels) has to be taken into account.

    Perhaps you want to know how to accelerate or tune it from your C code. This is highly operating system specific.

    On recent Linux systems, you could use the readahead, madvise (with mmap) and others system calls.

    Often, you can simply read in advance a file (perhaps just with cat yourfile > /dev/null) and your program would then run faster on Linux.

    Try for instance running twice the wc word counting utility on some big file. The second run usually goes much faster than the first.

提交回复
热议问题