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

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 表示的是直接缓存区
    }
}

  

原文地址:https://www.cnblogs.com/dongyaotou/p/14414196.html