• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

instatiating a C++ class through JNI

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to instantiate a C++ class from within my Java program using JNI. I want to instatiate the class once, and then call a function within the class a number of times, in which the results obtained from the previous time the function was run would be used the next time the function was run. By instantiating tha class, my hope is that the variable values would stay within the class, and therefore would not need to be passed.
It is not an option to pass the variable between the C++ and Java code, since I am working with matrices and JNI does not support passing matrices.
Thanks!
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the book "The Java Native Interface" by Sheng Liang it talks about passing arrays of objects, and since an array is an object, you can have arrays of arrays; and they can be used to implement matrices.
It describes class descriptors like "[[[D" which means "double [][][]", now that's a 3d matrix no?.
-Barry
I got this via http://www.codesaw.com
Sorry, dumb me, I forgot the copyright. Go get codesaw and checkout the examples from the book.
[ October 25, 2002: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, double[][][] is not exactly the same as a matrix. It is actually an array of double[][], which is an array of double[], which is an array of double. All those double numbers might be spread out all over memory, and they might not all be the same size (double[0][0].length could be 3 while double[0][1].length might be 127).
A matrix is usually considered to be a contiguous block of memory that is organized as a rectangular block (or whatever a multi-dimensional rectangle is called).
You can "fake" it by passing a large double[k*l*m] and the sizes of the "sides" (k, l, and m). Or you can pass a double[][][] and check it for consistent sizes and copy it to/from a contiguous block.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dave wrote:

A matrix is usually considered to be a contiguous block of memory that is organized as a rectangular block (or whatever a multi-dimensional rectangle is called).


Now you are looking inside the box.
I can also consider a matrix as a list of lists,
then I have an ideal implementation of a sparse matrix. Or if I want to implement a triangular matrix I can use a double[][] as we talked about before.
However, if I put my C/C++, Fortran, Pascal hats on, I agree with you , sort of...
-Barry
 
reply
    Bookmark Topic Watch Topic
  • New Topic