

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
16 messages in net.java.dev.jna.usersRe: [jna-users] Crash JVM call functi...| From | Sent On | Attachments |
|---|---|---|
| Sylvain ZUNINO [GMAIL] | May 18, 2009 6:40 am | |
| Timothy Wall | May 18, 2009 7:00 am | |
| Sylvain ZUNINO [GMAIL] | May 18, 2009 7:46 am | |
| Sylvain ZUNINO [GMAIL] | May 18, 2009 9:56 am | |
| Timothy Wall | May 18, 2009 10:04 am | |
| Sylvain ZUNINO [GMAIL] | May 18, 2009 10:14 am | |
| Timothy Wall | May 18, 2009 11:00 am | |
| Sylvain ZUNINO [GMAIL] | May 18, 2009 11:43 am | |
| Sylvain ZUNINO [GMAIL] | May 18, 2009 11:50 am | |
| Timothy Wall | May 18, 2009 12:02 pm | |
| Sylvain ZUNINO [GMAIL] | May 18, 2009 12:34 pm | |
| Timothy Wall | May 18, 2009 12:37 pm | |
| Sylvain ZUNINO [GMAIL] | May 19, 2009 12:33 am | |
| Timothy Wall | May 19, 2009 1:27 am | |
| Sylvain ZUNINO [GMAIL] | May 19, 2009 1:35 am | |
| Timothy Wall | May 19, 2009 2:18 am |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | Re: [jna-users] Crash JVM call function many times | Actions... |
|---|---|---|
| From: | Timothy Wall (twal...@dev.java.net) | |
| Date: | May 18, 2009 12:37:23 pm | |
| List: | net.java.dev.jna.users | |
You will need to map "free" from the C library, if you used "malloc" to allocate it.
On May 18, 2009, at 3:35 PM, Sylvain ZUNINO [GMAIL] wrote:
Thanks,
I'll try to free the Memory of my pointer .... but in the documentation, I try to find some examples to free the memory of a Pointer but I don't find it.... Is there a simple way to make it ??? Or is there a sample or a doc I can read to understand how I can make that (free à Pointer Object).
Regards,
Le 18 mai 09 à 21:02, Timothy Wall a écrit :
You could pass in a buffer, which is then returned after it is populated. Or you can capture the return value as a Pointer, extract the string, and then free the memory.
Depends on what your function is actually doing.
On May 18, 2009, at 2:51 PM, Sylvain ZUNINO [GMAIL] wrote:
Thank's for your response, how can I remove this memory leak, with a free I presume but how can I implemete that in JNA ?? Should I change my return type to Memory or pointer ou IOBuffer ??? And how can I free the pointer, memory or buffer after I read it ???
regards,
Le 18 mai 09 à 20:00, Timothy Wall a écrit :
You have a memory leak, which may or may not be the cause of your crash. The returned pointer will never be freed (JNA copies the data when it creates the String).
On May 18, 2009, at 1:15 PM, Sylvain ZUNINO [GMAIL] wrote:
Ok my cfunction returm this :
char *res = (char *)malloc(MAX_RET_CHAR * sizeof(char)); strcpy(res, ""); ... plus more strncat(... and strcpy(...
at the end of the function I return (return res)
regards Le 18 mai 09 à 19:04, Timothy Wall a écrit :
Assuming your native function looks like this:
char* cfunction(char* s1, char* s2, char** s3, int len);
you need to look at the function's definition to see what it is returning. If you don't have the code, read the docs. If you don't have docs, then you'll have to present both types of code (Java and native) side by side to determine what's different (assuming that you have working native code).
On May 18, 2009, at 12:56 PM, Sylvain ZUNINO [GMAIL] wrote:
How can I know Where and how is the memory behind the retrurned char * allocated ?
Regards,
Le 18 mai 09 à 16:01, Timothy Wall a écrit :
Where and how is the memory behind the returned char* allocated?
The memory behind each of the Java String parameters is only valid for the duration of the native call.
On May 18, 2009, at 9:40 AM, Sylvain ZUNINO [GMAIL] wrote:
Hello,
I implemente JNA to call a C function which return a char *.
public interface MYCFunction extends Library { MYCFunction INSTANCE = (MYFunction)Native.loadLibray(JNA_LIB_PATH, MYCFunction.class); String cfunction(String param1, String parm2, String[]param3, int nbOfParams3); }
I call more than 10000 times this function in a program :
for (int i=0; i<15000; i++) { String param1= "param1"; String param2= "param2"; String[] param3= { "param3_1", "param3_2" }; String res = MYCFunction.INSTANCE.cfunction(param1, param2, param3, param3.length);
........ }
My C program work well when I try It with a main (15000 times no problems). But when I test with JNA I'have a JVM crash at the 9998 or 10003 iterations.
What I'm wrong ???
Regards, Sylvain







