per ByteBuffer.asDoubleBuffer() spec:
"The new buffer's position will be zero, its capacity and its limit will be the number of bytes remaining in this buffer rounded down to the nearest multiple of eight .."
However, capacity() returns number_of_bytes/8.
-----------------------------
public static void test() {
int size = randomSize(); // randomSize() returns random int value
DoubleBuffer d = ByteBuffer.allocate(size).asDoubleBuffer();
int cap = d.capacity();
int pos = d.position();
int lim = d.limit();
System.out.println(d.getClass().getName() +
": size=" + size +
", cap=" + cap +
", lim=" + lim +
", pos=" + pos);
}
-----------------------------
result:
java.nio.ByteBufferAsDoubleBufferB: size=945, cap=118, lim=118, pos=0
-----------------------------
Similar behavior for other view buffers (CharBuffer, IntBuffer ..).
"The new buffer's position will be zero, its capacity and its limit will be the number of bytes remaining in this buffer rounded down to the nearest multiple of eight .."
However, capacity() returns number_of_bytes/8.
-----------------------------
public static void test() {
int size = randomSize(); // randomSize() returns random int value
DoubleBuffer d = ByteBuffer.allocate(size).asDoubleBuffer();
int cap = d.capacity();
int pos = d.position();
int lim = d.limit();
System.out.println(d.getClass().getName() +
": size=" + size +
", cap=" + cap +
", lim=" + lim +
", pos=" + pos);
}
-----------------------------
result:
java.nio.ByteBufferAsDoubleBufferB: size=945, cap=118, lim=118, pos=0
-----------------------------
Similar behavior for other view buffers (CharBuffer, IntBuffer ..).