A very basic jni question - are values copied?

A

aaronfude

Hi,

When an array is created in the native code and returned to java is it
returned by reference or by copy?

Sorry for not being able to find the answer to this very basic question
in the standard places.


Aaron Fude
 
C

Christian Ziech

Hi,

When an array is created in the native code and returned to java is it
returned by reference or by copy?

Sorry for not being able to find the answer to this very basic question
in the standard places.


Aaron Fude

Well I don't think that either is the correct answer. From your native
point of view you only have an "identifer" representing your
java-object. That's why you always act on the enviroment-variable. So
the situation is that you always only hold a reference in your
C(++)-Code to the real java-object. The bad thing about those
"identifers" is that they can be different each time a native method is
called for each object.
Hoped that this helped you a bit (further I hope that I didn't tell you
rubbish - all is afaik)

Christian
 
A

Ann

Hi,

When an array is created in the native code and returned to java is it
returned by reference or by copy?

Sorry for not being able to find the answer to this very basic question
in the standard places.


Aaron Fude

From my book learnin, all parameters and return values are passed
by copy, BUT WAIT THERE'S MORE. If the parameter/ret val is an
Object (array is an Object) then what is copied is the reference
to the object. So the array is itself not copied, you just get
a reference to it; it lives in the heap. Of course I have not tried it
myself, I use int and float.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top