首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

Java直接(堆外)内存使用详解

读写数据 在直接内存中,通过allocateDirect(int byte_length)申请直接内存。这段内存可以理解为一段普通的基于Byte的数组,因此插入和读取都跟普通的数组差不多。...举个例子: ByteBuffer buffer = ByteBuffer.allocateDirect(1024); buffer.putChar('a'); System.out.println(buffer...final Buffer rewind() { position = 0; mark = -1; return this; } 使用案例 ByteBuffer buffer = ByteBuffer.allocateDirect...注意每次写入数据的时候,position都会自动加上写入数据的长度,指向下一个该写入的起始位置: 下面看看如何写入一段byte[]或者字符串: ByteBuffer buffer = ByteBuffer.allocateDirect...ByteBuffer buffer = ByteBuffer.allocateDirect(10); buffer.put(new byte[]{1,2,3,4}); System.out.println

1.4K91
领券