Game Development Reference
In-Depth Information
See also
F Implementing portable memory-mapped iles
F Working with in-memory iles
Implementing portable memory-mapped iles
Modern operating systems provide a powerful mechanism called the memory-mapped iles.
In short, it allows us to map the contents of the ile into the application address space. In
practice, this means we can treat iles 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 ind out more about memory mapping, the reader may refer to the mmap() function
documentation.
How to do it...
1. In Windows, memory-mapped iles are created using the CreateFileMapping()
and MapViewOfFile() API calls. Android uses the mmap() function, which works
pretty much the same way. Here we declare the RawFile class implementing the
iRawFile interface.
RawFile holds a pointer to a memory-mapped ile and its size:
ubyte* FFileData;
uint64 FSize;
2. For the Windows version, we use two handles for the ile and memory-mapping
object, and for the Android, we use only the ile handle:
#ifdef _WIN32
HANDLE FMapFile;
HANDLE FMapHandle;
#else
int FFileHandle;
#endif
 
Search WWH ::




Custom Search