3 messages in net.java.dev.jna.users[jna-users] Freeing returned memory
FromSent OnAttachments
Neil C SmithJun 25, 2009 5:34 am 
Timothy WallJun 25, 2009 6:19 am 
Neil C SmithJun 25, 2009 7:07 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:[jna-users] Freeing returned memoryActions...
From:Neil C Smith (ne@neilcsmith.net)
Date:Jun 25, 2009 5:34:53 am
List:net.java.dev.jna.users

Hi,

I'm using JNA to work on a binding to the Jack Audio Connection Kit at the moment as I need access to the API for a current project, and while there is an existing project using custom JNI (JJack) it doesn't offer the level of access to the underlying API that I'm looking for. There is a little extra overhead from using JNA, but it's definitely workable (low latency in a realtime thread), and that's without trying direct mapping yet!

Anyway, I've got a question concerning a number of methods that return an array of strings ( as const char ** ). According to the Jack API, I need to free the returned memory, so I'm returning them as a Pointer in the JNA interface and creating a String[], but then what's the best way to free this memory? I tried the method of wrapping the free() method in the CLibrary as has been suggested previously, but this crashes the VM. However, if I create the free() method in the JackLibrary interface, it all works fine. I don't know enough about C to know if this is normal to access a function through a library that's been compiled against. Is this way of doing it liable to break?

btw - JNAJack is going up at http://code.google.com/p/java-audio-utils/ - the download is just a 'proof of concept', but the code I'm working on is in the SVN repo.

Thanks and best wishes,

Neil