Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Memory-mapped files?

Are Memory-mapped files in Java like Memory-mapped files for Windows? Or is it only emulation based on memory and file common operations in Java?

like image 584
Edward83 Avatar asked Nov 23 '10 22:11

Edward83


People also ask

How the files are mapped into memory?

A memory-mapped file contains the contents of a file in virtual memory. This mapping between a file and memory space enables an application, including multiple processes, to modify the file by reading and writing directly to the memory.

Is writing to a memory-mapped file faster?

Accessing memory mapped files is faster than using direct read and write operations for two reasons. Firstly, a system call is orders of magnitude slower than a simple change to a program's local memory.

Are memory mapped files thread safe?

Yes. If one thread changes part of the data in the mapping, then all other threads immediately see that change. You need to ensure the threads coordinate their changes so no thread is accessing an inconsistent view (eg.

Why are memory mapped files used in games?

Benefits of Memory Mapped FilesAccessing RAM is faster than disk I/O operation and hence a performance boost is achieved when dealing with extremely large files. Memory mapped files also offer lazy loading which equated to using a small amount of RAM for even a large file.


1 Answers

It uses the OS support for memory mapped files.

I'm trying to find documentation to back that up, but I haven't found anything conclusive yet. However, various bits of the docs do say things like this:

Many of the details of memory-mapped files are inherently dependent upon the underlying operating system and are therefore unspecified. The behavior of this method when the requested region is not completely contained within this channel's file is unspecified. Whether changes made to the content or size of the underlying file, by this program or another, are propagated to the buffer is unspecified. The rate at which changes to the buffer are propagated to the file is unspecified.

If everything were just emulated, there'd be no need for such unspecified behaviour.

like image 164
Jon Skeet Avatar answered Oct 23 '22 01:10

Jon Skeet