Advantages of mmap vs fileinput

前端 未结 1 553
臣服心动
臣服心动 2021-02-10 09:39

I read that mmap is advantageous than fileinput, because it will read a page into kernel pagecache and shares the page in user address space. Whereas, fileinput actually brings

相关标签:
1条回答
  • 2021-02-10 10:15

    mmap takes a file and sticks it in RAM so that you can index it like an array of bytes or as a big data structure.

    Its a lot faster if you are accessing your file in a "random-access" manner -- that is doing a lot of fseek(), fread(), fwrite() combinations.

    But if you are just reading the file in and processing each line once (say), then it is unlikely to be significantly faster. In fact, for any reasonable file size (remember with mmap it all must fit in RAM -- or paging occurs which begins to reduce the efficiency of mmap) it probably is indistinguishable.

    0 讨论(0)
提交回复
热议问题