문제

I am trying to read a large file in x,y,z. Typically it runs into gbs of data. I have created memory mapped file using 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).
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.

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

char buff[10000];
file.read(buff,10000);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top