This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: Storing C++ data in an instance field using CNI?
- From: Andrew Haley <aph at redhat dot com>
- To: David Daney <ddaney at avtrex dot com>
- Cc: Paul Gear <paul at gear dot dyndns dot org>, java at gcc dot gnu dot org
- Date: Tue, 25 May 2004 10:22:49 +0100
- Subject: Re: Storing C++ data in an instance field using CNI?
- References: <40B1E532.8000805@gear.dyndns.org><40B224C8.7030204@avtrex.com>
David Daney writes:
> 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.
Please, if you're going to use an integral type, use a long. I once
spent more than a month converting a huge code base that used ints to
store pointers.
The other thing you can do if using an integral type, is:
foo bar (int /*PTR*/ first, int /*PTR*/ second)
and you can then mechanically convert from one to t'other with a
trivial script.
Andrew.