[libvirt] Memory free in libvirt JNA
Claudio Bley
cbley at av-test.de
Thu Oct 11 15:36:14 UTC 2012
At Thu, 11 Oct 2012 08:37:23 +0000,
Benjamin Wang (gendwang) wrote:
>
> Hi Claudio,
> Sorry for my late response.
> I have gone through Claudio's solution. It's good. But I think this is not a common solution. There are two points:
> 1. This solution must use Pointerbyreference to encapsulate the
> Pointer. This is not clean.
Yes, as I said, this adds another level of indirection --- which is
pretty useless in Java.
> 2. Libvirt provides virFree method. But a common library could not
> provide memory management functions.
Sorry, I don't get your point here.
> My proposal is as following:
> 1. Add a new Class Libc.java
> public interface Libc extends Library{
> Libc INSTANCE = (Libc) Native.loadLibrary("c", Libc.class);
>
> public void free(Pointer p);
> }
Not every platform has a shared library called "c". On Windows this
would be msvcrt.dll for the Microsoft runtime. So, you would need to
branch on the platform to load whatever library seems appropriate.
Also, I just discovered that since version 3.3.0 JNA provides a public
free method itself.
Since I get crashes when using callback functions with JNA 3.2.7 in
certain circumstances it is better just to require a newer version of
JNA, IMHO.
I'll post a few patches with improvements and memory fixes tomorrow.
--
AV-Test GmbH, Henricistraße 20, 04155 Leipzig, Germany
Phone: +49 341 265 310 19
Web:<http://www.av-test.org>
Eingetragen am / Registered at: Amtsgericht Stendal (HRB 114076)
Geschaeftsfuehrer (CEO): Andreas Marx, Guido Habicht, Maik Morgenstern
More information about the libvir-list
mailing list