ByteBuffer.hasArray() is returning false and I cannot get anything out
of ByteBuffer.array(). Is there a way to get the array from
ByteBuffer. I saw that this method has been implemented only in
classes extended from ByteBuffer like ShortBuffer, etc.
What is the best way to have bytes allocated directly from Java,
passed on to C and get the data in a byteArray?
Thanks for your help.
/Michael
> --
> You received this message because you are subscribed to the Google Groups "android-ndk" group.
> To post to this group, send email to andro...@googlegroups.com.
> To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.
>
>
"Direct" byte buffers don't have a byte[] associated with them; the
storage is external to the VM. The array() operation doesn't work.
To access from C, Michael's answer is correct (though I'd tend to
leave them as a jbyte* just to remind you whence they came).
To access from Java as an array, you'd need to allocate a new byte[]
and copy the data over. For 10MB of data this isn't a great plan --
large allocation, expensive copy. If the number of accesses is small,
the various get/position calls will suffice.