The Cygnus Native Interface for C++/Java Integration | ||
---|---|---|
Prev | The Cygnus Native Interface for C++/Java Integration | Next |
New Java objects are allocated using a class-instance-creation-expression:
new Type ( arguments )The same syntax is used in C++. The main difference is that C++ objects have to be explicitly deleted; in Java they are automatically deleted by the garbage collector. Using CNI, you can allocate a new object using standard C++ syntax. The C++ compiler is smart enough to realize the class is a Java class, and hence it needs to allocate memory from the garbage collector. If you have overloaded constructors, the compiler will choose the correct one using standard C++ overload resolution rules. For example:
java::util::Hashtable *ht = new java::util::Hashtable(120);
void *_Jv_AllocBytes
(jsize size);