0

I can memory-map a whole file using the boost::interprocess package:

boost::interprocess::file_mapping* fm = new file_mapping(FilePath, boost::interprocess::read_only);
boost::interprocess::mapped_region* mr = new mapped_region(*fm, boost::interprocess::read_only);
char* bytes = static_cast<char*>(mr->get_address());

However this maps the whole file. I have a 30GB file- which won't fit in to main memory. Is there any way I can use the same boost library to map from position 0 to x and then I can map again from position x+1 to 2*x etc?

user997112
  • 29,025
  • 43
  • 182
  • 361
  • http://www.boost.org/doc/libs/1_37_0/doc/html/boost/interprocess/mapped_region.html - anything wrong with the offset and size params? – Mat Jan 05 '14 at 07:23
  • @Mat nothing wrong- just didnt see them. Thank you – user997112 Jan 05 '14 at 07:33
  • Note that tt does not matter (much) whether the file will "fit in to main memory", because the kernel will not read pages from disk until you access them, and it will drop pages if you do not access them for a while and the RAM is needed for something else. (You might get better efficiently by only mapping the pieces you need, since that is a strong hint to the kernel about what pages to keep/drop... But it is not required for correctness, even if your system has much less than 30GB of RAM.) – Nemo Jan 05 '14 at 07:40

0 Answers0