문제

I am trying to use boost to map a file onto memory having 3 floats per row (x,y,z coordinates of points). I am trying to store the data in cl_float3 type (for openCL) but it seems not to work. This is my code:

cl_float3 *data;
boost::iostreams::mapped_file_source file;
size = 785444;    // size of the file
int numBytes = size*sizeof(cl_float)*3;
file.open(filename,numBytes);
if(file.is_open()) {
    data = (cl_float3*)file.data();
    file.close();
}

Its giving access violation error for reading violation when I try to use data array. Any help?

도움이 되었습니까?

해결책

You're closing the file as soon as you open it. I haven't read the documentation for boost's memory mapped files, but you probably need to leave the file open.

if (file.is_open()) {
    data = (cl_float3*) file.data();
    file.close(); // remove this line
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top