Java Memory Map File

Source: Internet
Author: User

    • 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.