Implementing portable memory-mapped files
Modern operating systems provide a powerful mechanism called the memory-mapped files. In short, it allows us to map the contents of the file into the application address space. In practice, this means we can treat files as usual arrays and access them using C pointers.
Getting ready
To understand the implementation of the interfaces from the previous recipe we recommend to read about memory mapping. The overview of this mechanism implementation in Windows can be found on the MSDN page at http://msdn.microsoft.com/en-us/library/ms810613.aspx.
To find out more about memory mapping, the reader may refer to the mmap()
function documentation.
How to do it...
In Windows, memory-mapped files are created using the
CreateFileMapping()
andMapViewOfFile()
API calls. Android uses themmap()
function, which works pretty much the same way. Here we declare theRawFile
class implementing theiRawFile
interface.RawFile
holds a pointer to a memory-mapped file and its...