Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

How find out how many dimensions an objectArray has?

 
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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++?
 
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22649
126
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
No matter. Try again. Fail again. Fail better. This time, do it with this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic