Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2006

Tip: Looking for answers? Try searching our database.

JNI - which is faster?

Thread view: 
Edsoncv - 14 Aug 2006 14:27 GMT
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
Bill Medland - 14 Aug 2006 22:30 GMT
> 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++"?)
Signature

Bill Medland

Edsoncv - 15 Aug 2006 13:36 GMT
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

> > I'm developping a JNI and I would like to know which is faster:
> >
[quoted text clipped - 8 lines]
> know whether to pass the array itself or ...?  (What do you mean by
> "calling this array from c++"?)
Bill Medland - 15 Aug 2006 18:31 GMT
> Sorry, I wasn't clear in my question.
>
[quoted text clipped - 8 lines]
> 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.

>> > I'm developping a JNI and I would like to know which is faster:
>> >
[quoted text clipped - 11 lines]
>> --
>> Bill Medland

Signature

Bill Medland



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.