www.delorie.com/gnu/docs/gcc/gcj_34.html   search  
 
Buy the book!


Guide to GNU gcj

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

10.7 Object allocation

New Java objects are allocated using a class instance creation expression, e.g.:

 
new Type ( ... )

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 Java object using standard C++ syntax and the C++ compiler will 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);

Function: void* _Jv_AllocBytes (jsize size)
Allocates size bytes from the heap. The memory is not scanned by the garbage collector but it freed if no references to it are discovered.


  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003