Multiple Threads reading from the same file

前端 未结 3 1313
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-14 19:38

I have a xml file that needs to be read from many many times. I am trying to use the Parallel.ForEach to speed this processes up since none of that data being read in is re

3条回答
  •  醉梦人生
    2020-12-14 20:23

    Depending on the size of the file and the type of reads you are doing it might be faster to load the file into memory first, and then provide access to it directly to your threads.

    You didnt provide any specifics on the file, the reads, etc so I cant say for sure if it would address your specific needs.

    The general premise would be to load the file once in a single thread, and then either directly (via the Xml structure) or indirectly (via XmlNodes, etc) provide access to the file to each of your threads. I envision something similar to:

    1. Load the file
    2. For each Xpath query dispatch the matching nodes to your threads.

    If the threads dont modify the XML directly, this might be a viable alternative.

提交回复
热议问题