Efficiently reading a very large text file in C++

前端 未结 4 1672
攒了一身酷
攒了一身酷 2020-12-02 16:13

I have a very large text file(45GB). Each line of the text file contains two space separated 64bit unsigned integers as shown below.

4624996948753406865 10214715013

4条回答
  •  旧时难觅i
    2020-12-02 16:42

    I can only guess that the bottleneck is in:

    string str(memblock);
    

    -Because you allocate a 45MB long segment in memory.

    You should read the file line by line, as described in here:

    • Read file line by line

    In order to profile your program, you can print clock() between each line, as described in:

    • Easily measure elapsed time

提交回复
热议问题