ByteBuffer versus byte[]

I would like to bring up an important issue about using byte[] versus ByteBuffer variables in code. With byte arrays you have no freedom over memory allocation, it is always on the heap. In contrast, ByteBuffers subclasses can provide direct access to arbitrary memory. For instance, a VRAMByteBuffer could allow access to VRAM, and maybe even a PCIByteBuffer to access the various onboard buffers on PCI cards. To summarise, ByteBuffers are more flexible than byte[] and can potentially provide a lower level of memory access.

Therefore, I would like to propose that everyone should examine their sources to see whether they could replace any usage of byte[] with ByteBuffer. For example, FSFile read/writes in terms of byte[], i.e. to and from the heap. I propose FSFile should read/write ByteBuffers instead (note you dont need int off or int len either with a ByteBuffer). I also suggest some type of MemoryByteBuffer extends ByteBuffer implements MemoryResource class.

I think a widespread use of ByteBuffers in the low-level JNode APIs would not only bring a level of transparency to memory handling between subsystems, but is vital to having a high performance NIO implementation that can take advantage of non-heap memory.

I agree with you

I think it more Object Oriented to use a ByteBuffer that byte[]
and it's more powerfull as you said.
The next week, I will study it for FS in particular for cache for block device :
- replacing the notion of byte[] by some classes like Sector, Cluster ... all inheriting from ByteBuffer seams to be a good idea

ByteBuffer could have functions like : copy, split, move, convert to/from byte[], getChar(int index), setChar(int index, char value), fillChar, getInt(int index), setInt(int index, int value), fillInt(int value) ...

Fabien