15 messages in net.java.dev.jna.usersRe: [jna-users] Override Pointer.fina...
FromSent OnAttachments
bb...@cox.netJun 26, 2007 9:11 am 
Timothy WallJun 26, 2007 12:52 pm 
Wayne MeissnerJun 26, 2007 7:43 pm 
Ben ChaseJun 26, 2007 8:39 pm 
Wayne MeissnerJun 26, 2007 10:33 pm 
Timothy WallJun 27, 2007 5:08 am 
Timothy WallJun 27, 2007 5:20 am 
Rick GoldsteinJun 27, 2007 8:50 am 
Timothy WallJun 27, 2007 9:59 am 
Ben ChaseJun 27, 2007 7:26 pm 
Timothy WallJun 28, 2007 3:56 am 
bb...@cox.netJun 28, 2007 4:43 am 
bb...@cox.netJun 28, 2007 5:37 am 
bb...@cox.netJun 28, 2007 6:18 am 
Wayne MeissnerJun 28, 2007 7:41 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] Override Pointer.finalize to reclaim Native resources?Actions...
From:bb...@cox.net (bb@cox.net)
Date:Jun 28, 2007 6:18:51 am
List:net.java.dev.jna.users

Okay, so, eating my own dogfood, I introduced this class: import com.sun.jna.Pointer; public class WrappedPointer { private Pointer pointer; protected Pointer getPointer() { return pointer; } protected void setPointer(Pointer p) { pointer = p; } } And then I made all of my other appropriate classes extend it. The result of
course was that everywhere I'd said "pointer" in my code it now says
"getPointer()". (If JNA would embrace this WrappedPointer class, those would
instead have changed to "this", along with changes to the method parameters in
the .dll Interface, gaining type safety.) Everywhere I'd said variously
"foo.getPointer()" or "bar.getHandle()" or "baz.pointer" or "fubar.handle", I'm
now consistently saying "bar.getPointer()". (If JNA would embrace
WrappedPointer, I think those would become just "foo" and "bar" and "baz" and
"fubar".)

Another interesting change was that all (or almost all) of the classes that now
extend WrappedPointer no longer have to import com.sun.jna.Pointer. (They all
still needed ...PointerByReference, I think.)

Finally, one idiom that emerged repeatedly (but this may just be a consequence
of the particular .dll I'm using) was this: PointerByReference pHandle = new PointerByReference(); Media.INSTANCE.createFooHandle(pHandle,...); setPointer(pHandle.getValue()); // This line is the repeated idiom. So, I'm always wanting setPointer() to take a PointerByReference instead of a
Pointer, because I'm always stashing the pointer retrieved from .dll. I doubt
that rates as enough of an idiom to warrant being a facet of WrappedPointer.
And I'm trying to decide if there is some harm introduced if this method setPointer(PointerByReference pp) { setPointer(pp.getValue()); } was added to a JNA-internal version of WrappedPointer. And I think I can just
get that idiom myself by extending WrappedPointer, and then doing all my other
extends from that, right? No biggy on this last point about noticing this idiom. I just thought it was
interesting to see the same scrap of code crop up repeatedly... In fact, I
don't think I have much use for the vanilla settter "setPointer(Pointer p);",
except perhaps if I wanted to set the stashed pointer to some null value.

- Ben