The only time it is safe for the C side to access the byte[] is during
the call where the byte[] is passed as an argument. Once the native
call returns, the memory representing the byte[] to the native call is
no longer valid for native access.
You can certainly use the same byte[] object over and over again.
On May 21, 2009, at 5:04 PM, Roger Pack wrote:
Hmm. The kicker is that I believe I was doing something equivalent to
class A
byte[] b;
end
instantiating b with stuff, passing it into JNA, then later passing it
in with different data, and this time somewhere between java (where I
printed out the data--was fine) and c (printed out the data) it became
corrupted. Is that what you were referring to? If I use some byte[]
once should I abandon it after use?
-=r
On Thu, May 21, 2009 at 12:38 PM, Timothy Wall
<twal...@dev.java.net> wrote:
data passed via primitive array (e.g. byte[]) is only valid for the
duration
of the call. If you want something permanently shared between Java
and
native, you'll need to use Memory or a direct NIO buffer, and
periodically
synch changes.
you should definitely not hold a reference to the byte[]-originated
memory,
whether the object is long-lifed or not, because it's only a
temporary view
onto the array.
On May 21, 2009, at 2:04 PM, Roger Pack wrote:
Currently with 3.0.9, at least, sometimes when I pass (long lifed)
byte[] through...after say 5 minutes I pass them through, they're
good in java land, but corrupted in C land. Any thoughts?
-=r