I have a method in C++ that takes an array of doubles as an argument. I’m calling this method from Java and need to pass an array of doubles. The C++ routine reads and modifies the values of the array and I need those updated values in Java. How do I do this?
For example, take the C++ routine:
void myMethod( double *values, int size ) {
for ( int i=0; i < size; i++ ) {
values[i] = 2*values[i];
}
}
And the Java code:
double[] values = { 1.3, 1.1 };
myMethod(values,values.length);
System.out.println(values[0]); // prints 2.6
I guess a call to myMethod cannot be made like the call above… or can it? And what is necessary in Swig to make this work. If I cannot make a call like the one above, how do I get my values to the C++ code?
Use carrays.i!
See Swig docs on carrays
These two lines create the following code in my module:
Which allows me to use C arrays in Java… this solves my needs and is the best solution for my problem. Thanks everyone for your answers!