How many threads for reading and writing to the hard disk?

后端 未结 7 2264
清酒与你
清酒与你 2021-02-14 16:32

i am developing an application that gathers a list with all the files of the hard drive and also afterwards it does write files to the hard drive.

I want to ask : what i

7条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-14 16:51

    One thread. If you are reading AND writing at the same time AND your destination is a disk different from your source, then 2 threads. I'll add that if you are doing other operations to the files (for example decompress) the decompress part can be done on a third thread.

    To make some examples (I'm ignoring Junctions, Reparse Points...)

    • C: to C: 1 Thread TOTAL
    • C: to D: same physical disk, different partitions: 1 Thread TOTAL
    • C: to D: different physical disk: 2 Thread TOTAL

    I'm working on the presumption that a Disk can do ONE operation at a time, and each time it "multitasks" switching between different reads/writes it loses in speed. Mechanical disks have this problem (but technically NCQ COULD help). Solid state disks I don't know (but I know that USB sticks are VERY slow if you try to do 2 operations at a time)

    I have searched how you do it... I haven't found any "specific" examples, but I have some links to Windows API where you could start:

    • Displaying Volume Paths: http://msdn.microsoft.com/en-us/library/cc542456%28VS.85%29.aspx

    • GetVolumePathName: http://msdn.microsoft.com/en-us/library/aa364996(v=VS.85).aspx

    • GetVolumeInformationByHandleW http://msdn.microsoft.com/en-us/library/aa964920(v=VS.85).aspx

提交回复
热议问题