Jump to content
Excelsior Forums
ganesan

TypesDifferentException: Non-homogenous array

Recommended Posts

Hi,

I have to pass  ( Point ** ) type to a dll.

I have a java class Point extending Structure. I can not create a two diemsional array like

Point[][] pointArrayArry = new Point[r][c].

While r is known c keeps varying for every r. So, I declare

Point[][] pointArrayArry = new Point[r][].

In a loop from 0..r-1, I assign the coloumns. Essentially, the number of columns is different for each row. When I try to create

Argument  plolygons =  Argument.create    ("Point **" , pointArrayArry  ) ;

I get a TypesDifferentException: Non-homogenous array.

Pls suggest a solution.

Thanks,

ganesan

Share this post


Link to post
Share on other sites

Hello,

Only rectangular arrays can be passed to external functions, because multi-dimensional arrays in C/C++ are *plain*.

For example, in C for array char[2][5] should be allocated a single chunk of memory 10 bytes length.

In Java, you can create multi-dimensional non-rectangular array, because it is represented as array of pointers to 1-dimensional arrays, so char[2][5] is actually 3 arrays: one array containing pointers to other 2 arrays and 2 arrays with chars.

So you should create a rectangular array before passing it into external function via xFunction. You may, for example, count the maximal length of second dimension, create two-dimensional rectangular array [length_of_first_dimension][max_length_of_second_dimension] , copy elements from source array and pass rectangular array to external function.

-AlexM

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×