Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #19001
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeder2.ecngs.de!ecngs!feeder.ecngs.de!xlned.com!feeder1.xlned.com!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!feed.news.schlund.de!schlund.de!news.online.de!not-for-mail |
|---|---|
| From | Philipp Kraus <philipp.kraus@flashpixx.de> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: JNI return jobjectArray |
| Date | Mon, 1 Oct 2012 00:23:55 +0200 |
| Organization | 1&1 Internet AG |
| Lines | 79 |
| Message-ID | <k4aghk$45u$1@online.de> (permalink) |
| References | <k4a9gd$usp$1@online.de> <k4af7c$tdo$1@dont-email.me> |
| NNTP-Posting-Host | p4fc60383.dip0.t-ipconnect.de |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=iso-8859-1; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-Trace | online.de 1349043572 4286 79.198.3.131 (30 Sep 2012 22:19:32 GMT) |
| X-Complaints-To | abuse@einsundeins.com |
| NNTP-Posting-Date | Sun, 30 Sep 2012 22:19:32 +0000 (UTC) |
| User-Agent | Unison/2.1.9 |
| Xref | csiph.com comp.lang.java.programmer:19001 |
Show key headers only | View raw
On 2012-09-30 23:56:57 +0200, markspace said:
> On 9/30/2012 1:23 PM, Philipp Kraus wrote:
>> Hello,
>>
>> I hope this question is not OT.
>>
>> I create a JNI call for this Java method
>>
>> class myclass {
>>
>> void native mymethod( Double[] x )
>> }
>>
>> so the parameter x should be a call-by-reference, I would set x in the
>> native JNI function:
>>
>> void mymethod( JNIEnv *jenv, jclass jcls, jobjectArray& jarg )
>> {
>> // do something
>> jobjectArray t = .....
>>
>> jarg = t;
>> }
>>
>> How can I set the jobjectArray& back, so the data is return in the
>> parameter x?
>
>
> You can't. Java doesn't have a pass-by-reference call scheme, at all.
> Java uses only pass by value. You could:
>
> 1. Return the new array as a return value.
> 2. Create a reference to a reference so you can replace the 2nd one:
>
> > class myclass {
> >
> > void native mymethod( Double[][] x )
> > }
>
> will give you a pointer to an array which you can then modify.
>
> A Google search for "Java pass by reference" will give you lots of
> details. Maybe add "jni" to get some clues more specific results for
> your particular situation.
You are not right, because the problem is not the Java side, it is the
JNI (C/C++) side, so under C/C++ exists call-by-reference.
In detail I have got a native (C) methode, that shows in Java:
class myclass {
native void mymethod( Double[] x, Double[][] y )
}
The JNI glue code generates a
void mymethod (JNIEnv* jnv, jclass jcls, jobjectArray arg1, jobjectArray arg2 )
So the reference to the underlaying heap object is passed in the JNI
code parameters arg1 & arg2,
so I would modify this two heap adresses.
If I call in Java this code:
Double[] x = null;
Double[][] y = null;
myclass.mymethod(x, y);
// x & y are now filled with data
in x & y should be create a new array object, so I need a
GlobalReference on the heap of the VM
and push back the reference. I can create the global object on the VM
heap, but how can I push back
the reference
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
JNI return jobjectArray Philipp Kraus <philipp.kraus@flashpixx.de> - 2012-09-30 22:23 +0200
Re: JNI return jobjectArray markspace <-@.> - 2012-09-30 14:56 -0700
Re: JNI return jobjectArray Philipp Kraus <philipp.kraus@flashpixx.de> - 2012-10-01 00:23 +0200
Re: JNI return jobjectArray markspace <-@.> - 2012-09-30 19:21 -0700
Re: JNI return jobjectArray Lew <lewbloch@gmail.com> - 2012-09-30 21:14 -0700
Re: JNI return jobjectArray markspace <-@.> - 2012-10-01 08:32 -0700
Re: JNI return jobjectArray "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2012-10-01 09:39 +0100
Re: JNI return jobjectArray Roedy Green <see_website@mindprod.com.invalid> - 2012-10-01 10:21 -0700
Re: JNI return jobjectArray Steven Simpson <ss@domain.invalid> - 2012-10-01 23:46 +0100
csiph-web