Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #19005

Re: JNI return jobjectArray

Newsgroups comp.lang.java.programmer
Date 2012-09-30 21:14 -0700
References <k4a9gd$usp$1@online.de> <k4af7c$tdo$1@dont-email.me> <k4aghk$45u$1@online.de> <k4auo2$fvf$1@dont-email.me>
Message-ID <8ae235a8-d70a-45c8-b94f-8f7190b940f1@googlegroups.com> (permalink)
Subject Re: JNI return jobjectArray
From Lew <lewbloch@gmail.com>

Show all headers | View raw


markspace wrote:
> Philipp Kraus wrote:
>> You are not right,
> 
> I'm not right?  And yet...
> 
>> heap, but how can I push back the reference
> 
> ...the problem still exists.
>
>> In detail I have got a native (C) methode, that shows in Java:
> 
> Truthfully, there is not enough detail here for me to guess what the 
> problem really is.  You're showing method signatures but no code.

What he did show was a parameter passed from Java as a C++ reference.

Does that even work? Java doesn't have anything like C++ references to pass.

That being the advice the OP blew off immediately.

>> If I call in Java this code:
>>
>> Double[] x = null;

'x' is equivalent to a pointer, not a reference.

Pardon my ignorance, but what if you used a pointer in the native code
instead of a reference?

> > Double[][] y = null;
>>
>> myclass.mymethod(x, y);

Java convention calls for type names to start with an upper-case letter
and use camel case.

> No this will not work.  I guess I was not specific enough: *you* have to 
> create a reference to the array reference you want to modify.  That 

Well, in C++ terms, wouldn't that be a pointer?

> doesn't happen if the parameter is null.
> 
>    Double x = { {1.2} };
> 
> Now you have something to modify.  Java does NOT have pass by reference, 
> you must do it yourself.  I did a Google search, and I didn't see the 
> solution, so here I guess is some lost knowledge.  This is Java, you'll 
> have to translate to C++ on your own:
> 
> class Example {
> 
>    // manual "pass by reference"
> 
>    void makeNewDoubleArray( Double [][] x ) {
>      x[0] = new Double[] { 1.1, 2.2, 3.3 };
>    }
> 
>    public static void main( String... args ) {
>      Double[] y = {0.0};
>      Double[][] wrapper = { {} };
>      wrapper[0] = y;           // pack
>      makeNewDoubleArray( wrapper );
>      y = wrapper[0]            // unpack
>      System.out.println( java.util.Arrays.deepToString( y ) );
>    }
> }
> 
> Code is untested; watch out for silly errors.

I am ignorant of the ways of JNI, so my question might be extraordinarily 
off base.

-- 
Lew

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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