[
http://issues.apache.org/jira/browse/DIRMINA-165?page=comments#action_12370086
]
Robert Greig commented on DIRMINA-165:
--------------------------------------
I think (?) I agree with Federico. I don't see why we need to lose the pooling
of the original buffer in the case where you slice the buffer, although
obviously you need to prevent auto expand.
In the implementation I did as a quick test, I created a subclass of
DefaultByteBuffer - I called it SlicedByteBuffer - which had its own reference
count and held a reference to the original (parent) byte buffer it came from.
When you call slice on a DefaultByteBuffer, that increment the reference count
and returns a SlicedByteBuffer. Calling release() on the SlicedByteBuffer
decrements the slice's reference count and once that reaches zero it calls
release() on the parent.
So in Trustin's example:
buf = ...;
dupBuf = buf.duplicate(); // this increments the ref count of buf and
returns a subclass that has different release() implementation
buf.release(); // ref count is still 1 so buffer is not released into the
pool
newBuf = ByteBuffer.allocate( ... ); // this is now fine
dupBuf.release(); // this releases both the dupBuf and buf instances
Obviously SlicedByteBuffer cannot be pooled nor can it autoexpand.
> Easy and performant copy of the ByteBuffer
> ------------------------------------------
>
> Key: DIRMINA-165
> URL: http://issues.apache.org/jira/browse/DIRMINA-165
> Project: Directory MINA
> Type: Improvement
> Versions: 0.9, 0.8.2, 0.8.1, 0.8
> Reporter: Federico Bonelli
> Priority: Minor
> Fix For: 0.9.3
> Attachments: ByteBuffer.java, HubServer_broadCastTCPmessages.zip
>
> Until now if you wish to broadcast a message you must create by your own the
> bytebuffer copies, it would be better to provide a ByteBuffer.asReadOnly()
> method that create a copy that share the data with the original ByteBuffer
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira