Re: java calling C

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> I have been so far successful in passing java numbers
> (all types)  to C routines. What I have failed at is
> dealing with passing and returning Strings. I have
> tried to pass byte[] and char[] stuff instead and the
> results have been less than thrilling. I am trying to
> deal with some things in C that cannot be dealt with
> nicely in Java. I believe the best way to pass a true
> String object and know how to deal with that.
> 
>    1)   can someone point me to what the String struct
> looks like?
>         I need two things - the string array itself
> and its length()
>    2)   how do I translate a unicode short to a char +
> vice versa?
>    3)   how can I malloc a new String in C so that
> Java garbage collection will free it later?
> 
> Thanks for any clues you can provide - even pointing
> me to the correct source code to start with is a good
> start (I am using gcc 3.3.3 currently as it is
> compatible with other things that break in 3.4 - GCC
> does not break, they do as the standards are
> enforced).

It is JAVA specific question (JNI (Java native interface)), there is a
lot of information about it on sun.com pages.
http://java.sun.com/j2se/1.5.0/docs/guide/jni/

I think here you'll find all needed information.

> 3)   how can I malloc a new String in C so that Java garbage collection will free it later?

There is a finalize( ) method for this purpose. However java garbage
collector might never start its job, if it has lots of spare memory.
And GC is only about java used memory, it does'nt bother about any
other resources. For more information about java GC you can read
"Thinking in Java" (http://www.mindview.net/)

>  2)   how do I translate a unicode short to a char + vice versa?
Try using iconv (libiconv) it can convert almost everything...

Arturas M.


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux