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)
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.