Unnecessary copy?
Norman Maurer
norman.maurer at googlemail.com
Tue Oct 18 03:39:13 EDT 2011
2011/10/18 Bill Burke <bburke at redhat.com>:
> I'm looking at the code for NioWorker.read(). I notice that a
> ChannelBuffer is created, then the underlying ByteBuffer is copied into
> this ChannelBuffer via the buffer.setBytes(0, bb); call.
>
> Why isn't a wrapped ChannelBuffer created around the ByteBuffer? Any
> reason why the whole NIO ByteBuffer is copied?
>
> Thanks
>
> --
> Bill Burke
Hi Bill,
I think the copy is done because it use a "Pool" of ByteBuffers.
Otherwise you would not be able to release it in a quick manner.
See:
https://github.com/netty/netty/blob/3.2/src/main/java/org/jboss/netty/channel/socket/nio/NioWorker.java#L319
https://github.com/netty/netty/blob/3.2/src/main/java/org/jboss/netty/channel/socket/nio/NioWorker.java#L343
Bye,
Norman
More information about the netty-users
mailing list