When I read from files in C++(11) I map them in to memory using:
boost::interprocess::file_mapping* fm = new file_mapping(path, boost::interprocess::read_onl
Simply create an istringstream from your memory mapped bytes and parse that using :
const std::string stringBuffer(bytes, region->get_size());
std::istringstream is(stringBuffer);
typedef boost::tokenizer< boost::escaped_list_separator > Tokenizer;
std::string line;
std::vector parsed;
while(getline(is, line))
{
Tokenizer tokenizer(line);
parsed.assign(tokenizer.begin(),tokenizer.end());
for (auto &column: parsed)
{
//
}
}
Note that on many systems memory mapping isn't providing any speed benefit compared to sequential read. In both cases you will end up reading the data from the disk page by page, probably with the same amount of read ahead, and both the IO latency and bandwidth will be the same in both cases. Whether you have lots of memory or not won't make any difference. Also, depending on the system, memory_mapping, even read-only, might lead to surprising behaviours (e.g. reserving swap space) that don't that sometimes keep people busy troubleshooting.