Memory map file mappedbytebuffer

The DirectByteBuffer mentioned in the previous article inherits from MappedByteBuffer

The definition of MappedByteBuffer:

A direct byte buffer whose content is a memory-mapped region of a file.

Direct cache, the content is a memory mapped file.

Create a test class

public class NioTest9 {
    public static void main(String[] args) throws Exception {
        RandomAccessFile randomAccessFile = new RandomAccessFile("NioTest9.txt","rw");
        FileChannel fileChannel = randomAccessFile.getChannel();
        MappedByteBuffer mappedByteBuffer = fileChannel.map(FileChannel.MapMode.READ_WRITE, 0,5);
        mappedByteBuffer.put(0,(byte)‘a’);
        mappedByteBuffer.put(3,(byte)‘b’);

        randomAccessFile.close();
    }
}

 Create NioTest9.tex file

Share pictures

 Run the program and open it with Notepad

share picture

The operation is off-heap memory, off-heap memory Writing to the file is controlled by the operating system.

public class NioTest9 {
    public static void main(String[] args) throws Exception {
        RandomAccessFile randomAccessFile = new RandomAccessFile("NioTest9.txt","rw");
        FileChannel fileChannel = randomAccessFile.getChannel();
        MappedByteBuffer mappedByteBuffer = fileChannel.map(FileChannel.MapMode.READ_WRITE, 0,5);
        mappedByteBuffer.put(0,(byte)‘a’);
        mappedByteBuffer.put(3,(byte)‘b’);

        randomAccessFile.close();
    }
}

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 2799 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.