This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Creating a C/C++ library using Java


Juan Altmayer Pizzorno wrote:

has anybody thought about creating a C/C++ library using Java and gcj?

Do you mean creating a library which can be called from a C/C++ application? If so then yes, its quite possible using the CNI or JNI invocation APIs - see http://gcc.gnu.org/onlinedocs/gcj/Invocation.html for details.

I haven't looked into the internals closely yet, but it seems to me that at
least the garbage collector would make it difficult (right?).  I am not
sure whether there would be actual conflicts, or whether the library would
just behave in an unexpected way (e.g., seem to initiallly leak memory).

In general there shouldn't be any problems with the GC. It should be able to co-exist peacefully with native code that uses malloc, etc. One thing to be aware of is that you shouldn't store pointers to Java objects in C++ objects allocated with C++ new/malloc/etc, as the reference won't be seen by the GC and could result in premature collection. Pointers to Java objects should only be stored on the stack or in other Java objects.

regards

Bryce.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]