• Post Reply Bookmark Topic Watch Topic
  • New Topic

How find out how many dimensions an objectArray has?  RSS feed

 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When i pass a multi-dimensional array from java to c/c++, how can the c/c++ code discover how many dimensions it has? Also, how do I discover the size of each dimension (array) from c/c++?
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java does not have multi-dimensional arrays. It only has single-dimensional arrays. However, the element type of a single-dimensional array can be an array, allowing the illusion of multi-dimensional arrays.

For how to access Java arrays from C++, you should read the appropriate section of the JNI specification.
 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Peter Chase:
Java does not have multi-dimensional arrays. It only has single-dimensional arrays. However, the element type of a single-dimensional array can be an array, allowing the illusion of multi-dimensional arrays.

For how to access Java arrays from C++, you should read the appropriate section of the JNI specification.


Ah, so if I have an ObjectArray passed to my JNI, and I ask for size, it'll be giving me the "dimensions"?

For example, if I'm passed:


and i ask for the size like:


jsize will be 3? Can i pass a jobjectArray to the method GetArrayLength?
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No.

I think you need to read up on multidimensional arrays (or the lack thereof) in Java. Perhaps read this.

Getting the length via JNI is exactly the same as getting the length via ".length" in Java.
 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Peter Chase:
No.

I think you need to read up on multidimensional arrays (or the lack thereof) in Java. Perhaps read this.

Getting the length via JNI is exactly the same as getting the length via ".length" in Java.


I read it and I'm not sure I follow what you're getting at. In JNI, the proper way to get the size of an array is not the same as in java. Rather, Java's own documents recommend using GetArrayLength. So how do I get the length of a jobjectArray "exactly the same" as in Java? Could you please post some example code? Thanks!
[ November 09, 2007: Message edited by: Dan Bizman ]
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The point is that if, in C++, you do GetArrayLength() on a particular Java object reference, what you get is the same as doing ".length" on the same Java object reference, in Java.

I'm at work, so I can't go writing example code. Perhaps someone else will.
 
Rob Spoor
Sheriff
Posts: 21052
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's the Java way, using java.lang.reflect.Array and assuming that there will be no zero element arrays:

This is the simplest case possible, in reality it will probably be harder.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!