5 messages in net.java.dev.jna.usersRe: [jna-users] pass three char data'...
FromSent OnAttachments
Landon WilliamsJul 15, 2008 12:26 pm 
Michael Brewer-DavisJul 16, 2008 9:24 am 
will...@gmail.comJul 16, 2008 1:15 pm 
Michael Brewer-DavisJul 16, 2008 1:48 pm 
Nikolas LotzJul 17, 2008 1:32 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] pass three char data's back to javaActions...
From:Nikolas Lotz (nlo@nde.ag)
Date:Jul 17, 2008 1:32:35 am
List:net.java.dev.jna.users

In this case, you'd ideally delete/free the memory later on--not sure how that works from within JNA. On a small scale, you might be able to live with this memory leak. Others may have advice on delete/free?

--- interface -------------------------------------

import com.sun.jna.Library; import com.sun.jna.Pointer;

public interface LibCNative extends Library {

public void free(Pointer p);

public Pointer malloc(long size); }

--- implementation --------------------------------

import com.sun.jna.Native; import com.sun.jna.Platform; import com.sun.jna.Pointer;

public class LibC {

private static LibCNative lib;

static { try { String LIB_NAME = Platform.isWindows() ? "msvcrt" : "c"; lib = (LibCNative) Native.loadLibrary(LIB_NAME, LibCNative.class); } catch (Throwable e) { throw new RuntimeException(e.getMessage()); } }

public static void free(Pointer p) { if ((p != null) && (!p.equals(Pointer.NULL))) { lib.free(p); p = Pointer.NULL; } }

public static Pointer malloc(long size) { return lib.malloc(size); } }

--- example ---------------------------------------

Pointer p = LibC.malloc(12345); LibC.free(p);

Vorsitzende des Aufsichtsrates: Angelika Mozdzen Sitz und Registergericht: Hamburg, HRB 90934 Vorstand: Jens-U. Mozdzen USt-IdNr. DE 814 013 983