The ZeroByteBuffer package is designed to address and manage some of the limitations of the java.nio.ByteBuffer Object. These limitations had caused serious performance and synchronization problems.
Performance Issues
- Direct ByteBuffers are abstractions of direct native memory instead of Java heap managed memory. Because they are not managed by the JVM's garbage collection, a lack of pooling often can look like a memory leak. In fact, it was a memory leak in early 1.4 JDKs!
- When the JDKs write out non-direct ByteBuffers, they create direct ByteBuffers, copy all the data from the non-direct to the direct ByteBuffers, and write out the direct ByteBuffer. Some JDKs cache this direct ByteBuffer and some don't. If they do not cache it, see bullet above. If they do...they don't do a good job of utilizing it. So, we have to abstract this out.
Synchronization issues
Now that we have established that pooling is needed for performance, we can see that pooling has serious implications when it comes to synchronization.
- Duplicates and slices require reference counts on the ByteBuffer.
- Buffers need read only capabilities because one entity may not know who its passing the buffer to and may not want data to be overwritten.