Fastest file reading in C

前端 未结 7 1456
耶瑟儿~
耶瑟儿~ 2020-12-05 00:50

Right now I am using fread() to read a file, but in other language fread() is inefficient i\'v been told. Is this the same in C? If so, how would faster file reading be done

7条回答
  •  不知归路
    2020-12-05 01:21

    What's slowing you down?

    If you need the fastest possible file reading (while still playing nicely with the operating system), go straight to your OS's calls, and make sure you study how to use them most effectively.

    1. How is your data physically laid out? For example, rotating drives might read data stored at the edges faster, and you want to minimize or eliminate seek times.
    2. Is your data pre-processed? Do you need to do stuff between loading it from disk and using it?
    3. What is the optimum chunk size for reading? (It might be some even multiple of the sector size. Check your OS documentation.)

    If seek times are a problem, re-arrange your data on disk (if you can) and store it in larger, pre-processed files instead of loading small chunks from here and there.

    If data transfer times are a problem, perhaps consider compressing the data.

提交回复
热议问题