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]

Storing C++ data in an instance field using CNI?


is it possible using CNI to store C++ data in the object as an
instance field?

As earlier mentioned the best way to do this is to store the struct address in a long java variable. Why long? Well, to be honest 64-bit systems will eventually become the norm which means you will probably have to convert your program later. Think ahead now and write it for 64 bit systems in mind since that will still work with 32 bit systems (just get alot of warnings during compilation about casting int to long).

Also remember to override the finalize method of your Java object that is storing the native struct to call a native method to free/delete the native struct. Very important!! If you dont do this C/C++ will not deallocate the memory reserved for your native struct when the Java class is GCed.


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