Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Java
JNI troubles (newbie)
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Stefan Schulz, post: 600885"] I would suggest you build a "Java Wrapper" around the native resource, maybe something like this: public abstract class PointerWrapper { private final long ptr; protected PointerWrapper(long ptr){ this.ptr = ptr; } public final long getPointer(){ if (freed){ throw new IllegalStateException(); } } public boolean isValid(){ return !freed; } public final void free(){ if (freed){ throw new IllegalStateException(); } freed = true; free(ptr); } protected final void finalize() throws Throwable { free(); } protected abstract void free(long pointer); }} If the resource may persist longer, you might even try making free() private. WARNING: This was written from memory. It may contain typos, or even logical errors, but this is the general way i would go about things. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Java
JNI troubles (newbie)
Top