Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading a large text file in parallel in C++

Tags:

c++

I have a large textfile.. I want to read this file and perform some manipulation in it..

This manipulation occurs independently on each line. So basically, I am looking for some function which can do this parallel.

void readFile(string filename){

  //do manipulation

}

That do manipulation can happen in parallel.

Agreed that this can be done easily using hadoop but that is an overkill solution. (Its large file but not that large that I need hadoop for this...)

How do I do this in C++?

like image 934
frazman Avatar asked Sep 07 '25 16:09

frazman


1 Answers

I would use mmap for that. mmap gives you memory-like access to file so you can easly read in parallel. Please look at another stackoverflow topic about mmap. Be careful when usin non-read-only pattern with mmap.

like image 198
spinus Avatar answered Sep 09 '25 08:09

spinus