For more readings about memory mapped file, It’s usually more efficient to use regular file I/O routines to perform read/write operations on large files. When mapping large files into virtual memory to perform I/O on them, be cognizant of the fact that every address you burn in virtual memory is another than can’t be used by your app. Something to be careful of, though, is depleting virtual memory. Have a look at the MapViewOfFile() Win32 API for some basic info and some pointers on how to get going with this. If you’d rather search a file or perform minor in-place modifications of it using simple pointer dereferencing and value assignment rather than invoking file I/O operations, you can certainly do so. Ken also said that: Memory-mapped files are also used to process files as though they were data. I think the major advantage of using memory mapped file for file io is that you reduce the amount of data copying required over traditional methods of reading a file. Since the memory-mapped file is handled internally in pages, linear file access (as seen, for example, in flat file data storage or configuration files) requires disk access only when a new page boundary is crossed, and can write larger sections of the file to disk in a single operation. Applications can access and update data in the file directly and in-place, as opposed to seeking from the start of the file or rewriting the entire edited contents to a temporary location. Secondly, in most operating systems the memory region mapped actually is the kernel's page cache (file cache), meaning that no copies need to be created in user space.Ĭertain application level memory-mapped file operations also perform better than their physical file counterparts. Firstly, a system call is orders of magnitude slower than a simple change of program's local memory. Accessing memory mapped files is faster than using direct read and write operations for two reasons. According to, The primary benefit of memory mapping a file is increased I/O performance, especially when used on small files. Here is an example when using memory mapped file for file IO is useful: In this case, the customer could not use File IO API (WriteFile/ReadFile) to do asynchronously IO, so he uses file mapping to simulate "lazy writing". For reading a file it is essentially useless because the disk is the big bottleneck. Using it for file IO is only useful in certain scenarios. MMF is also convenient for inter process communication scenarios.
0 Comments
Leave a Reply. |