Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > What types of variables can be passed with JNI?

Reply
Thread Tools

What types of variables can be passed with JNI?

 
 
Ramon F Herrera
Guest
Posts: n/a
 
      07-09-2005
I have an application whose purpose is to open, display and rezise TIFF
files.

My application is written mainly in Java, but it uses C/C++ through
JNI.

I purchased a OCR library which receives calls form the Java side using
_simple_ types of arguments such as int, floats and strings. For
instance, to have a file analized I just pass its filesystem path (i.e.
a string) to the C/C++ OCR library.

My next version has to provide some extended functionality and I wonder
if JNI is up to the task. More specifically, I would like to have
resizing features similar to those provided by Acrobat: click on a plus
sign and the image becomes bigger, type a percentage or move a sliding
tool and the images is resized.

After looking hard and long, it seems that the only libraries that can
perform that resampling with an acceptable level of quality and speed
are written in C/C++.

Now the question: as said above, I know I can pass an int or a string
between the Java side and the C/C++ side, but what about more complex
variables? Can I open a file in Java and pass some sort of handle to
it to the C library?

What are the limitations of JNI in terms of passing "objects" back &
forth?

TIA.

-Ramon F Herrera

 
Reply With Quote
 
 
 
 
Gordon Beaton
Guest
Posts: n/a
 
      07-09-2005
On 8 Jul 2005 20:57:36 -0700, Ramon F Herrera wrote:
> What are the limitations of JNI in terms of passing "objects" back &
> forth?


You can pass any Java types (primitives and object references) between
Java and your JNI library. Once in a native method however, you can
invoke any other C functions and pass whatever C data types you want.

If you open a File in Java, yes you can pass the resulting object to a
native method, however you will need to invoke Java methods from the
native code in order to read from the file. If you want to read the
file from C, consider opening it there as well (the java code can pass
it the path as a String).

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      07-09-2005
On 8 Jul 2005 20:57:36 -0700, "Ramon F Herrera" <(E-Mail Removed)>
wrote or quoted :

>Now the question: as said above, I know I can pass an int or a string
>between the Java side and the C/C++ side, but what about more complex
>variables? Can I open a file in Java and pass some sort of handle to
>it to the C library?


You write glue code in C or C++ to tie the two together. That code
calls your C methods to get work done. To talk to Java it uses a
rather peculiar puppetry, manipulating java objects in the Java
address space by remote control. You can set their fields, run their
methods, all with a clumsy syntax. you can also construct new Java
objects and pass parameters (e.g. C strings you have constructed) as
their arguments.

Either Java can call C, or slightly more complicated, C can call Java.

I have written a short essay describing how it all works. See
http://mindprod.com/jgloss/jni.html

The trick to success is to try to keep the interactions between the
sides to a minimum. Call C and STAY there as long as possible before
returning. There is a grievous overhead for a call that goes over the
Java/C boundary.

In other words, don't call a C method 1000 times getting one int back
each time. Instead call once and construct an array and pass that back
as a lump.



--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/...s_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      07-09-2005
On 8 Jul 2005 20:57:36 -0700, "Ramon F Herrera" <(E-Mail Removed)>
wrote or quoted :

> Can I open a file in Java and pass some sort of handle to
>it to the C library?


The C file handle is pretty useless in Java. What you would have to do
is write C wrapper methods to do your io, and call them from Java.


The easiest way to do the reverse would be the same, but you can
manipulate a file or InputStream object remotely from C just as you
can invoke the methods of any object.

--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/...s_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
Reply With Quote
 
Vit
Guest
Posts: n/a
 
      07-15-2005
There is another alternatice to JNI- xFunction, which is some easier in usage.
Have a look at
http://www.excelsior-usa.com/xfunction.html

Vit
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Put variables into member variables or function variables? tjumail@gmail.com C++ 9 03-23-2008 04:03 PM
Can XSD simple types be derived from complex types? Soren Kuula XML 2 12-01-2005 07:51 PM
Where are ref types that are members of value types stored? Sathyaish ASP .Net 2 05-22-2005 07:32 PM
Boost + Python C/API: Mixing python return types with boost return types Steve Knight Python 2 10-10-2003 10:11 AM
STD types vs C++ intrinsic types Jeremy Cowles C++ 5 08-19-2003 05:33 PM



Advertisments