- Memory-mapped files provide the fastest IO possible for Java, so high-performance Java applications should use "memory-mapped files" to persist data, especially for larger files, which are much faster than I/O streams, but small files are not necessarily.
- Memory-mapped files can load large files, the size of the file upper limit depends on the operating system (memory addressable range): 32-bit, not more than 4GB, that is 2^32 bit, 64-bit, you can almost map any file into memory and directly use Java Access.
- The memory-mapped file allows you to read and write memory directly using direct or Non-direct byte cache (byte buffer).
- A key advantage of a memory-mapped file is that the operating system is responsible for true read and write, even if your program hangs after it has just written to memory, and the operating system still writes the data in memory to the file system.
- Another more prominent advantage is the shared memory, the memory map file can be accessed by multiple processes at the same time, play a role of low latency shared memory.
Map the entire file or part of a file into memory so that Java accesses the data of the file you are loading directly from memory. The operating system is responsible for obtaining page requests and writing files, and the application only needs to process the memory data, which allows for very fast IO operations. (relative to the memory - mapped file: read and write files from disk )
The general usage is:
- Create a Randomaccessfile object RAF
- Raf.getchannel (). Map () method gets mapped memory file Mappedbyterbuffer object MBB
- Call the Mbb.put () or Mbb.get () method to write or read
Reference:
http://blog.csdn.net/napolunyishi/article/details/18214929
Java Memory Map File