ChannelBuffer to byte array

Shay Banon kimchy at gmail.com
Wed Mar 3 05:44:19 EST 2010


Agreed, this is why Java serialization works with final fields :). I meant
something else, which I now understand that I was wrong. For some unknown
reason to me, I thought that the HTTP request message, for example, does not
have its own copy of ChannelBuffer.

-shay.banon

On Wed, Mar 3, 2010 at 11:50 AM, "Trustin Lee (이희승)" <trustin at gmail.com>wrote:

> Hi Shay,
>
> I think it is safe even if you do not copy the content of the array if
> the happens-before condition meets.  For example, this is safe:
>
> Thread A:
>
>    sharedByteArray[0] = 1;
>    taskQueue.offer(something);
>
> Thread B:
>
>    taskQueue.poll(); // get something
>    assert sharedByteArray[0] == 1;
>
> For more information, read this article:
>
>    http://www.ibm.com/developerworks/library/j-jtp03304/
>
> HTH,
> Trustin
>
> Shay Banon wrote:
> > Just to clarify this (and correct me if I am wrong here Trustin), if
> > then, you are going to use that byte array in another thread (for
> > example, using the execution handler), then you have to copy it over.
> > For example, in your http request message handler which then delegates
> > the handling of the Http request to another thread.
> >
> > -shay.banon
> >
> > On Wed, Mar 3, 2010 at 7:56 AM, "Trustin Lee (이희승)"
> > <trustin at gmail.com <mailto:trustin at gmail.com>> wrote:
> >
> >     Adam,
> >
> >     Netty 3.2 adds array() and hasArray() to ChannelBuffer.
> >
> >     In 3.1, you can call toByteBuffer() which will not involve memory
> copy
> >     if possible.
> >
> >     HTH,
> >     Trustin
> >
> >     Adam Durana wrote:
> >     > Hi,
> >     >
> >     > I'm looking for the most efficient way to get a ChannelBuffer's
> data
> >     > in the form of a byte array.  The byte array will be only read from
> >     > and not modified.  Is the best way to use a ChannelBuffer's
> readBytes
> >     > method to copy the data into an array?  Or is there a way that
> doesn't
> >     > involve copying given that I'm not going to be modifying the array?
> >     >
> >     > Thanks,
> >     > Adam
> >     > _______________________________________________
> >     > netty-users mailing list
> >     > netty-users at lists.jboss.org <mailto:netty-users at lists.jboss.org>
> >     > https://lists.jboss.org/mailman/listinfo/netty-users
> >
> >     --
> >     what we call human nature in actuality is human habit
> >     http://gleamynode.net/
> >
> >
> >
> >     _______________________________________________
> >     netty-users mailing list
> >     netty-users at lists.jboss.org <mailto:netty-users at lists.jboss.org>
> >     https://lists.jboss.org/mailman/listinfo/netty-users
> >
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > netty-users mailing list
> > netty-users at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/netty-users
>
> --
> what we call human nature in actuality is human habit
> http://gleamynode.net/
>
>
>
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/netty-users/attachments/20100303/b78f5a6c/attachment-0001.html 


More information about the netty-users mailing list