What is the Fastest Method for High Performance Sequential File I/O in C++?

前端 未结 7 1741
囚心锁ツ
囚心锁ツ 2020-11-29 16:41

Assuming the following for...
Output:
The file is opened...
Data is \'streamed\' to disk. The data in memory is in a large contiguous buffer. It is

7条回答
  •  一向
    一向 (楼主)
    2020-11-29 17:28

    You will get the absolute fastest performance by using CreateFile and ReadFile. Open the file with FILE_FLAG_SEQUENTIAL_SCAN.

    Read with a buffer size that is a power of two. Only benchmarking can determine this number. I have seen it to be 8K once. Another time I found it to be 8M! This varies wildly.

    It depends on the size of the CPU cache, on the efficiency of OS read-ahead and on the overhead associated with doing many small writes.

    Memory mapping is not the fastest way. It has more overhead because you can't control the block size and the OS needs to fault in all pages.

提交回复
热议问题