判断是直接缓存区还是间接缓存区

package com.nio;

import java.nio.ByteBuffer;

/**
 * 五、直接缓存区与非直接缓存区
 * 非直接缓存区:通过allocate() 方法分配缓存区,将缓存区建立在jvm的内存中。
 * 直接缓存区:通过allocateDirect() 方法分配直接缓存区,将缓存区建立在物理内存中,可以提高效率
 */
public class TestBuffer1 {
    public static void main(String[] args) {
        //分配直接缓存区
        ByteBuffer buffer = ByteBuffer.allocateDirect(1024);
        System.out.println(buffer.isDirect());//true 表示的是直接缓存区
    }
}

  

 

posted on 2021-02-19 00:32  ~码铃薯~  阅读(33)  评论(0编辑  收藏  举报

导航