通过boost mapped_region / memory-mapped文件迭代?

时间:2012-12-13 21:57:02

标签: c++ boost

我有以下代码将文件加载到boost mapped_region:

file_mapping fm(FilePath, read_only);
mapped_region region(fm, read_only);
char * const data = static_cast<char *>(region.get_address());
  • 如何逐个字符地迭代所获得的数据?
  • 上面的代码有什么方法可以修改,所以我不使用char*指针,而是使用静态字符数组char c[x]

1 个答案:

答案 0 :(得分:1)

file_mapping fm(FilePath, read_only);
mapped_region region(fm, read_only);
char * const data = reinterpret_cast<char*>(region.get_address());

// Iterate through the data obtained, character (c) by character.
for(std::size_t n = 0; n < region.get_size(); ++n)
{
      char c = data[n];
}