8 messages in net.java.dev.jna.usersRe: [jna-users] Question on variable ...
FromSent OnAttachments
Jay WaltersMay 12, 2008 9:42 am 
Timothy WallMay 12, 2008 9:52 am 
Jay WaltersMay 12, 2008 11:05 am 
Jay WaltersMay 12, 2008 11:12 am 
Timothy WallMay 12, 2008 12:05 pm 
Timothy WallMay 12, 2008 12:10 pm 
Jay WaltersMay 12, 2008 12:39 pm 
Timothy WallMay 12, 2008 2:05 pm 
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] Question on variable length structures in Win32Actions...
From:Timothy Wall (twal@dev.java.net)
Date:May 12, 2008 12:10:16 pm
List:net.java.dev.jna.users

JNA only allocates native memory for Structure instances, freeing that memory when the Structure is GC'd. It does so internally for String arguments, but that's not something you have to worry about normally.

If you point a JNA Structure at native-allocated memory, it will use that memory to read/write and discard the pointer when the Structure is GC'd.

You could consider JNA as allocating memory as needed (and managing whatever memory it allocates based on Java object lifespan). JNA will use native pointers that you give it, generally leaving that memory alone w/r/t deallocation, making it your responsibility to feed it back to native code at some later point for proper disposal.

On May 12, 2008, at 2:12 PM, Jay Walters wrote:

So I guess the bit confusing me is the peer-ing aspect. In java I will always have an object. Java will allocate it (always me?) and that object will peer with a native object which sometimes I will allocate and sometimes will get allocated inside the native code. Does JNA ever allocate the java objects, or do I always have to do that?