简体   繁体   English

如何使用boost从内存映射文件访问内存块?

[英]How to access chunk of memory from memory mapped file using boost?

I am trying to read a large file in x,y,z. 我试图读取x,y,z中的大文件。 Typically it runs into gbs of data. 通常它会遇到gbs的数据。 I have created memory mapped file using Boost. 我使用Boost创建了内存映射文件。 However, I am still not very clear as how to access a chunk of memory from this file. 但是,我仍然不清楚如何从这个文件访问一块内存。

Boost provides function char* data() that returns pointer to the first byte of the buffer.(I get entire data as buffer). Boost提供函数char * data(),它返回指向缓冲区第一个字节的指针。(我将整个数据作为缓冲区)。
Is there a way by which I can read the data chunk by chunk. 有没有办法可以通过块读取数据块。 Ideally, I would like to read the data in chunks of say 10,000. 理想情况下,我想以10,000个块的形式读取数据。

Following is code. 以下是代码。

boost::iostreams::mapped_file_source file;
std::string filename("MyFile.pts");
unsigned size = 58678952192;  
file.open(filename, size);
int numBytes = size*sizeof(float)*3;  
cl_float3 *data = new cl_float3[size];
float * tmp = (float*)file.data();

for(int i = 0; i < size;i++)     
{
  data[i].x = tmp[i*3];
  data[i].y = tmp[i*3+1];
  data[i].z = tmp[i*3+2];
}
delete[] tmp;

boost::iostreams behave just like std::basic_iostream We can use unformatted IO boost :: iostreams的行为就像std :: basic_iostream我们可以使用未格式化的IO

char buff[10000];
file.read(buff,10000);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM