How to save reference to an native-object (c++)

C

Cengiz

Hi,
what i do in my program:
I have a class in Java. Some Methods of this class call another global
native-method written in c++ (in a DLL). This method in c++ instances
a class. How can i do it, that at the next invocation i can use the
same instance without instantiate it new ?
 
P

pete kirkham

Cengiz said:
Hi,
what i do in my program:
I have a class in Java. Some Methods of this class call another global
native-method written in c++ (in a DLL). This method in c++ instances
a class. How can i do it, that at the next invocation i can use the
same instance without instantiate it new ?

Have a field in the Java class which is wide enough to contain the
address of the native object's pointer, which is passed as an argument
to/accessed inside the native method.


Pete
 
J

Joseph Millar

Hi,
what i do in my program:
I have a class in Java. Some Methods of this class call another global
native-method written in c++ (in a DLL). This method in c++ instances
a class. How can i do it, that at the next invocation i can use the
same instance without instantiate it new ?

Including Pete's approach (which I have used myself on
several ocassions), you can set a static field in the
C++ class and just retrieve it on entry to get the
instance pointer. Or set a DLL global variable.

In all of these instances, be sure you take thread
safety into consideration.

--Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top