如何保持在Java code A C ++对象?可能? [英] How to keep a C++ object inside Java code? Possible?
问题描述
首先,我有一个传统的C ++库,而我迁移我的应用程序到Android新用户界面。
First I've got a legacy C++ library, and I'm migrating my app to Android with new UI.
在运行时,可能有多个C ++动态创建和销毁的对象。我建立了一套JNI本地方法调用到图书馆来获取。但是,在我应该让那些C ++对象?我必须让他们的轨道,释放他们,如果他们是不必要的。
During runtime, there might be multiple C++ objects created and destroyed dynamically. I built a set of JNI native methods to call into library to get that. But where should I keep those C++ objects? I have to keep track of them and free them if they're unnecessary.
到目前为止,我只知道的Java不能引用到C ++对象。是否有可能使一个Java包装类,其中包括引用C ++对象?
So far I only knew Java can't reference to a C++ object. Is it possible to make a Java wrapper class which include a reference to C++ object?
感谢。
推荐答案
是的,这是可能的。您可以在一个简单的Java INT存储一个指针到C ++对象。这究竟是如何痛饮做到这一点。
Yes, it's possible. You can store a pointer to your C++ object in a simple java int. That's exactly how SWIG does that.
这篇关于如何保持在Java code A C ++对象?可能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!