Buffer
allocate()
public static ByteBuffer allocate(int capacity) {
if (capacity < 0)
throw new IllegalArgumentException();
// 堆内缓存区
return new HeapByteBuffer(capacity, capacity);
}public static ByteBuffer allocateDirect(int capacity) {
// 对外缓存区
return new DirectByteBuffer(capacity);
}HeapByteBuffer
HeapByteBuffer(int cap, int lim) {
super(-1, 0, lim, cap, new byte[cap], 0);
}ByteBuffer(int mark, int pos, int lim, int cap,
byte[] hb, int offset)
{
super(mark, pos, lim, cap);
this.hb = hb;
this.offset = offset;
}DirectByteBuffer
比较
Last updated