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 / First Aid / August 2005

Tip: Looking for answers? Try searching our database.

Avoiding copying an array in JNI

Thread view: 
Lin DeNoyer - 21 Aug 2005 14:57 GMT
I am building an interface to a C dll (also compiled as an so library in
linux).  This is my problem:

The operation performed by the dll/so file takes about 2 minutes to execute.  
In the past, when accessing this dll from C/C++/Matlab etc. code, I have always
(a) allocated the memory block needed for the operations (1-100 MBytes),
(b) put the call to the dll in a loop, telling it exactly what time slice it is
allowed to have for processing - asking it to return after that time slice, so
as not to lock up the user interface of the calling program.  
(c) The memory block keeps track of where it is in the processing - and so it
essentially runs in to background until done.
(d) The calling program keeps calling the dll until the dll says it is 100%
done.
(e) At 100% done, the result is removed from the memory block, and the
memory block freed.

The problem I am running into with JNI is that I am supposed to make a copy of
every array sent into the dll - else disaster - or so the book says.  But this
copy (twice - once on the way into the dll and again on the way out) - with
accompanying allocation of a new (big) block of memory - makes the processing
impossible.  REALLY IMPOSSIBLE!  We are talking about waiting hours -
maybe even overnight - for something that can be done in a few minutes.

So here is my question:  How can I allocate the big memory block in a way that
will avoid it being moved, so that I don't have to do the standard copy for
each JNI call into the dll?

LKD
Patricia Shanahan - 21 Aug 2005 15:08 GMT
> I am building an interface to a C dll (also compiled as an so library in
> linux).  This is my problem:
[quoted text clipped - 24 lines]
>
> LKD

Is there any possibility of running the computation in a separate
thread, at lower priority than the event handling thread, and any
threads the event handler depends on?

That way, preserving the computation's state when the GUI needs the
processor would be the operating system's problem, not yours. It would
be done much more efficiently, by leaving the data in memory.

Moreover, the OS would only run the GUI when it has something to do,
such as handling a user action. The computation would not be interrupted
unnecessarily just in case the GUI needs to do something.

Patricia
Lin DeNoyer - 21 Aug 2005 16:33 GMT
>Is there any possibility of running the computation in a separate
>thread, at lower priority than the event handling thread, and any
[quoted text clipped - 9 lines]
>
>Patricia

Thank you for that suggestion.  I am a rank amateur at all this, and so I will
now go away and learn about threads.

Lin


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.