Sure. Instead of putting a native pointer in a long or in a byte[], you just declare a class with a single field that contains the pointer. Everyone who needs a pointer makes a suitably named subclass, so they'll know what they're pointing to.
How is that more efficient than a byte array?
Here's a concrete example:
class SomeRandomLibraryClass { static { System.loadLibrary("SomeRandomJNILibrary"); }
private byte[] nativePointer;
private native byte[] initNativeData(...); private native void someNativeMethod(byte[] nativePointer, ...);
public SomeRandomLibraryClass(...) { ... nativePointer = initNativeData(...); }
public void someMethod(...) { someNativeMethod(nativePointer, ...) /** THE REAL CALL **/ } }
In the C code, we'll have:
JNIEXPORT void JNICALL Java_somepackage_someNativeMethod (JNIEnv *env, jobject this, jbyteArray nativePointer, ...)
{ void *ptr; (*env)->GetByteArrayRegion(env, nativePointer, 0, sizeof(void *), (jbyte *) &ptr); ... /* do whatever with ptr */ ... }
So, how is your opaque type more efficient (and portable)?
Etienne
-- Etienne M. Gagnon, Ph.D. http://www.info.uqam.ca/~egagnon/ SableVM: http://www.sablevm.org/ SableCC: http://www.sablecc.org/
_______________________________________________ Classpath mailing list [EMAIL PROTECTED] http://mail.gnu.org/mailman/listinfo/classpath