Storing C++ data in an instance field using CNI?
David Daney
ddaney@avtrex.com
Mon May 24 17:18:00 GMT 2004
Paul Gear wrote:
>Hi folks,
>>I've searched the archives & Google without finding an answer to this
>question: is it possible using CNI to store C++ data in the object as an
>instance field?
>>I need to store a struct defined in an external library within the
>object. Can i just define a field that is of type Object and then use
>that as a pointer? If i do this, do i need to use special malloc/free
>routines?
>>Thanks in advance,
>Paul
>http://paulgear.webhop.net
>>I think the traditional way to do it with JNI and CNI is to define an
int (or long if using 64 bit pointers) member in the java object that
will be casted to a pointer to the C++ data object. The C++ data object
would be allocated with operator new or malloc. You have to arrange to
delete/free it before the java object is GCed. This can be done from
the finalize method.
David Daney.
More information about the Java
mailing list