Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the 'correct' way to store a native pointer inside a Java object?

What is the 'correct' way to store a native pointer inside a Java object?

I could treat the pointer as a Java int, if I happen to know that native pointers are <= 32 bits in size, or a Java long if I happen to know that native pointers are <= 64 bits in size. But is there a better or cleaner way to do this?

Edit: Returning a native pointer from a JNI function is exactly what I don't want to do. I would rather return a Java object that represents the native resource. However, the Java object that I return must presumably have a field containing a pointer, which brings me back to the original question.

Or, alternatively, is there some better way for a JNI function to return a reference to a native resource?

like image 770
Daniel Cassidy Avatar asked Dec 03 '08 14:12

Daniel Cassidy


1 Answers

IIRC, both java.util.zip and java.nio just use long.

like image 137
Tom Hawtin - tackline Avatar answered Oct 04 '22 07:10

Tom Hawtin - tackline