How to QFile::map a binary file filled with double values
I'm having trouble understanding how
QFile::mapworks. The return value is a
uchar*, which I understand as an array of characters. In the documentation I don't see any arguments for specifying the type of file to map to (
In my case, I created a binary file filled with
doublevalues and now I want to map that to memory. Can someone provide a very brief example on how this is achieved?
I think that QFile::map create identical copy of content of a file or part of it into the memory - byte by byte. Every uchar is a byte from memory. So, it is up to you how to interpret the content of this part of the memory. If you map your whole file and it contain only doubles, I guess you can cast it like this:
uchar * map = file.map(0, size); double * dm = map; double dbl1 = *dm; double dbl2 = *dm; ...
Well, I'm not completely sure about this.
uchar * map = file.map(0, size); double * dm = reinterpret_cast<double*>(map); double dbl1 = *dm; double dbl2 = *dm;