How to scan through really huge files on disk?

后端 未结 8 2097
北荒
北荒 2020-12-09 18:14

Considering a really huge file(maybe more than 4GB) on disk,I want to scan through this file and calculate the times of a specific binary pattern occurs.

My thought

8条回答
  •  旧巷少年郎
    2020-12-09 18:38

    Although you can use memory mapping, you don't have to. If you read the file sequentially in small chunks, say 1 MB each, the file will never be present in memory all at once.

    If your search code is actually slower than your hard disk, you can still hand chunks off to worker threads if you like.

提交回复
热议问题