I have some trouble when visit mapped_region data.
First, I define a struct: (for stock quotes...)
struct bar{
double open,high,low,close;
size_t volume;
bar(double _open, double _high, double _low, double _close): open(_open),high(_high), close(_close), volume(_volume){}};
here is the sample.txt (I've also tried binary format) file for which I want to visit by iteration of bar type
89.26 89.47 89.25 89.47 563
89.47 89.56 89.27 89.47 284
89.46 89.56 89.26 89.33 264
using following code, I can read the character by character:
file_mapping m_file(filename,read_only);
mapped_region region(m_file,read_only);
char const* add= static_cast<char*> (region.get_address());
namely, for the first data, I would get 8 9 . 2 6, character by character using add[i]. This can be terrible workload. So I want to convert :
bar* myaddr=(bar*)(region.get_address()), where bar is define as the above..
so that I can have access to data by using :
myaddr->open (with an offset ).
For instance, now I want to visit the 3rd number in the second line, I just need:
(myaddr+1)->high
However, the result is really wired:
e.g 1.50656e-189, or sometimes 825303072 for (myaddr+2)->volume
In fact, if I convert to any time beyond char , there would be such error...
Question: How can I visit mapped data by using myaddr-> without error?
Thanks
That looks like a text file. If you read it as a memory mapped region you get text, not doubles. That is your problem.