且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在C#中读取超大文本文件的最快方法

更新时间:2021-11-18 09:48:15

如果您可以逐行执行此操作,则答案很简单:

If you can do this line by line then the answer is simple:

  1. 阅读一行.
  2. 处理该行.
  3. 写线.

如果希望它更快一点,则将它们放在三个BlockingCollections中,并指定上限(例如10),因此较慢的步骤永远不会等待较快的步骤.如果可以输出到其他物理光盘(如果输出到光盘).

If you want it to go a bit faster, put those in three BlockingCollections with a specified upper bound of something like 10, so a slower step is never waiting on a faster step. If you can output to a different physical disc (if output is to disc).

即使在询问过程是否逐行(两次)后,OP也会更改规则.

OP changed the rules even after being asked if the process was line by line (twice).

  1. 读取行以生成工作单元(打开以关闭标签).
  2. 工作单元.
  3. 写工作单元.