Search:
|
Access:
» NoodleGlue - Simplifying JNI Code GenerationRelated categories: Java | C/C++ TreeViewed: 13417 | Article date: 2005-12-13 15:21:08 NoodleGlue is a set of tools, which generates JNI code from a simple script and the C/C++ header files, and includes a library to manage the code at runtime. It was written in various stages with the aim to not only simplify the problems related to large JNI code projects, but also to manage the somewhat incompatible memory-management models of unmanaged C/C++ code and Java’s garbage collection mechanism. It is not perfect, but right now NoodleGlue can handle most features of C and C++ and, when using NoodleGlue-generated libraries, programmers should find it as easy to use their library in Java as they do in C or C++. Even better, NoodleGlue has now been open-sourced for everyone to use for free!
About the Autor
Tree is lead programmer at Noodleheaven and works on several disparate projects from Noodle, an interactive music player to server software to drive giant display technology. To contact the author: tree@noodleheaven.net JNI is the natural way to support native C or C++ library code in Java. However, writing the JNI interface for each function or class method can be extremely tedious and prone to error. When the underlying library is changing this can be even worse, as the need to edit the JNI code can turn into a full time job on a large project! NoodleGlue is a set of tools, which generates JNI code from a simple script and the C/C++ header files, and includes a library to manage the code at runtime. It was written in various stages with the aim to not only simplify the problems related to large JNI code projects, but also to manage the somewhat incompatible memory-management models of unmanaged C/C++ code and Java's garbage collection mechanism. It is not perfect, but right now NoodleGlue can handle most features of C and C++ and, when using NoodleGlue-generated libraries, programmers should find it as easy to use their library in Java as they do in C or C++. Even better, NoodleGlue has now been open-sourced for everyone to use for free! A reference-counting strategy can helpNoodleGlue works at runtime by having native and Java peer class objects. They are bound together by one of the key design features for Noodleglue: a simple reference management system. It is certainly not rocket science, but configuring NoodleGlue to require as little developer involvement as possible has not been easy. Java, with its lovely memory manager and C/C++, with their manual new/delete pattern, do not fit together too well. Some native libraries (our own internal ones included) use a memory management strategy using smart pointers. They use reference-counting to ensure objects are deleted without leaving pointers to non-existent objects when used properly. NoodleGlue runtime uses reference-counting to manage - as much as possible - the object management between C++ and Java peer objects. What all this means is that when a native object's reference count drops to 0, it will not be deleted straight away, but waits until the Java peer is garbage-collected. This works in reverse too: a Java object will not be garbage-collected until the native object no longer needs it to exist. This does not mean that your library has to support smart pointers; however, you will miss out on a couple of really cool features like sub-classing native classes directly in Java, where overloaded methods are called from C++.
|
|
Copyright C 2006 by Software Developer's Journal. All rights reserved.





SDJ Users:
Shopping Cart









