<div dir="ltr">Yea, that was my idea for pooling channel buffers, not to serialize directly to the socket :). Maybe wrapped internally or externally with a soft reference.<br><br><div class="gmail_quote">On Thu, Nov 11, 2010 at 4:10 AM, &quot;이희승 (Trustin Lee)&quot; <span dir="ltr">&lt;<a href="mailto:trustin@gmail.com">trustin@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">I don&#39;t think there&#39;s a way to avoid buffer allocation completely.  An<br>
object needs to be serialized into some form and we need some space to<br>
do that.  We can&#39;t write byte by byte during serialization because it<br>
will be very slow.<br>
<br>
If you want to reduce the cost of buffer allocation, you might want to<br>
pool it, but you have to be careful about concurrency issues.<br>
<br>
  PooledChannelBuffer buf = pool.acquire();<br>
  ...<br>
  ch.write(buf).addListener(new ChannelFutureListener() {<br>
      void operationComplete(...) {<br>
          buf.release();<br>
      }<br>
  });<br>
<br>
Actually, I think this could be part of Netty! :-)<br>
<br>
Shay Banon wrote:<br>
&gt; Hi,<br>
&gt;<br>
&gt;    I was wondering if there is a nice way to try and avoid buffer<br>
&gt; allocation when serializing objects. I have my own way of serializing<br>
&gt; objects, but the idea is very similar to ObjectEncoder, which allocates<br>
&gt; a new buffer for each written message. I understand that its very<br>
&gt; difficult to serialize directly to the socket in non blocking IO, but<br>
&gt; was wondering if there is a good way to not allocate a buffer each time<br>
&gt; but maybe reuse buffers.<br>
&gt;<br>
&gt;    I could build my own cache of buffers, get one before writing and<br>
&gt; release it when the write is completed. Wondering if there is a better<br>
&gt; way to do it...<br>
&gt;<br>
&gt; -shay.banon<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; netty-users mailing list<br>
&gt; <a href="mailto:netty-users@lists.jboss.org">netty-users@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/netty-users" target="_blank">https://lists.jboss.org/mailman/listinfo/netty-users</a><br>
<font color="#888888"><br>
--<br>
Trustin Lee - <a href="http://gleamynode.net/" target="_blank">http://gleamynode.net/</a><br>
<br>
<br>
</font><br>_______________________________________________<br>
netty-users mailing list<br>
<a href="mailto:netty-users@lists.jboss.org">netty-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/netty-users" target="_blank">https://lists.jboss.org/mailman/listinfo/netty-users</a><br></blockquote></div><br></div>