On Wed, May 21, 2008 at 11:00 AM, Eero Nevalainen <
[EMAIL PROTECTED]> wrote:

> I think that the above use case works fine when using heap buffers, as when
> there are no more references to the message object the sliced buffers should
> be freed as well. But would I need to do something extra
> to make it work with direct buffers?


>From the ByteBuffer Java Docs: "It is therefore recommended that direct
buffers be allocated primarily for *large*, *long-lived* buffers that are
subject to the underlying system's native I/O operations." Because of
the small and short-lived nature of buffers inside Mina, I don't see a
reason for using direct buffers at all. Afaik direct buffers make sence e.g.
for mapping large portions of files on a disk to direct memory for faster
multiple access - I doubt that using them for network packets results in
a performance gain (see also: DirectByteBuffer extends *MappedByteBuffer*).

However, I played around a bit with direct and heap buffers, testing some
possible cases that could lead to unexpected behaviour, but everything
worked fine with direct buffers, too, so there should be no problem. Direct
buffers support duplicate(), position(), limit(), all the
setters/getters and they have their own custom dealocator that will hook the
direct byte array to the wrapping directbytebuffer instance or even multiple
instances for duplicates (
http://dmi.ensica.fr/doc/Java/j2sdk-1_4_2-doc/docs/j2h/java/nio/DirectByteBuffer.java.html)
so this should basically work the same like gcing heap buffers. The
implementation seems to be mostly the same, just the underlying byte array
is "directly mapped".

Feel free to correct me if I'm wrong.

regards
Daniel

Reply via email to