JNI - which is faster?

E

Edsoncv

I'm developping a JNI and I would like to know which is faster:

Passing a big array to C++ (with JNI) or calling this array from c++.

Thanks
 
B

Bill Medland

Edsoncv said:
I'm developping a JNI and I would like to know which is faster:

Passing a big array to C++ (with JNI) or calling this array from c++.

Thanks
I think you will need to be clearer about what it is you are trying to do if
you want a meaningful reply.

Do you mean that you have a big array of primitive types (e.g. ints) in a
Java application and you are calling a function through JNI and you want to
know whether to pass the array itself or ...? (What do you mean by
"calling this array from c++"?)
 
E

Edsoncv

Sorry, I wasn't clear in my question.

I mean: A have a big array of doubles in Java( eg. "X") I have two
options:
1) Pass the array to C++ in the native functinon call. eg.
public static native void solveNLPnative(double X[]).

2) Define a getX() method in Java and call this method from C++.

Since this operation will be done many times and "X" could be huge, I
would like to know which of the options is faster.
Thanks
 
B

Bill Medland

Edsoncv said:
Sorry, I wasn't clear in my question.

I mean: A have a big array of doubles in Java( eg. "X") I have two
options:
1) Pass the array to C++ in the native functinon call. eg.
public static native void solveNLPnative(double X[]).

2) Define a getX() method in Java and call this method from C++.

Since this operation will be done many times and "X" could be huge, I
would like to know which of the options is faster.
Thanks

(Warning; I am still new to all this, but)

Personally I don't see that it should make any real difference. If it is
really important you will need to test both.

NB don't forget that in both cases you will actually get a reference to the
Java array itself and you will have to call GetDoubleArrayElements and
ReleaseDoubleArrayElements to get at the underlying array.

So an important question is whether you are merely reading the array or are
actually modifying it.

It seems to me that the potential choke is GetDoubleArrayElements, which you
are going to need whichever method you choose.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,263
Messages
2,571,062
Members
48,769
Latest member
Clifft

Latest Threads

Top