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


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

Re: JNI return jobjectArray

From markspace <-@.>
Newsgroups comp.lang.java.programmer
Subject Re: JNI return jobjectArray
Date 2012-09-30 19:21 -0700
Organization A noiseless patient Spider
Message-ID <k4auo2$fvf$1@dont-email.me> (permalink)
References <k4a9gd$usp$1@online.de> <k4af7c$tdo$1@dont-email.me> <k4aghk$45u$1@online.de>

Show all headers | View raw


On 9/30/2012 3:23 PM, 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.


> If I call in Java this code:
>
> Double[] x = null;
> Double[][] y = null;
>
> myclass.mymethod(x, y);


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 
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.



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