解析mmap()的 - 编辑文件 [英] parsing a mmap()-ed file

查看:348
本文介绍了解析mmap()的 - 编辑文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是最好的(最快)的方式通过mmap的-ED文件来分析?它包含了对数据(串INT),但我不能在它们之间persume空格/制表符/换行符号。

What would be the best (fastest) way to parse through a mmap-ed file? It contains pairs of data (string int), but I cannot persume number of whitespaces/tabs/newlines between them.

推荐答案

假设你已经mmaped整个文件(而不是大块 - 因为这将让生活awefully复杂),我会做类似如下..

Assuming you've mmaped the whole file in (rather than chunks - as that would make life awefully complicated), I'd do something like the following...

// Effectively this wraps the mmaped block
std::istringstream str;
str.rdbuf()->pubsetbuf(<pointer to start of mmaped block>, <size of mmaped block>);

std::string sv;
std::string iv;

while(str >> sv >> iv)
{
  // do stuff...
}

我觉得应该工作...

I think that should work...

警告这是实现定义的行为,请参阅这个答案一个更好的共做法。

WARNING This is implementation defined behaviour, see this answer for an altogether better approach.

这篇关于解析mmap()的 - 编辑文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆