jsr356-experts@websocket-spec.java.net

[jsr356-experts] Re: ByteBuffers versus Byte Arrays

From: Wenbo Zhu <wenboz_at_google.com>
Date: Fri, 10 Aug 2012 17:17:16 -0700

On Fri, Aug 10, 2012 at 12:54 PM, Bill Wigger <wigger_at_us.ibm.com> wrote:

> It looks like the APIs for send* and onMessage* are defined to use byte
> arrays. Can we use ByteBuffers instead of byte[] in these APIs? The
> reason being is that byte[] are always allocated from heap memory, but
> ByteBuffers can either be allocated, under the user's control, as nonDirect
> (heap memory) or Direct (native memory). Sometimes it is advantageous for
> the user to be using native memory and at least they should be given the
> flexibility to do so. byte[] can be wrapped into ByteBuffers and retrieved
> from ByteBuffers easily, so users can work with byte[] if they want to.
>
I'd support using ByteBuffer too, to avoid unnecessary copy. Our pre-spec
API started with ByteBuffer, but then switched to byte[] as we have legacy
ByteBuffer-like types written pre 1.4 ;)



>
> regards,
> Bill
>
> Bill Wigger
> Software Development
> IBM Research Triangle Park
>
>