16 messages in net.java.dev.jna.usersRe: [jna-users] Crash JVM call functi...
FromSent OnAttachments
Sylvain ZUNINO [GMAIL]May 18, 2009 6:40 am 
Timothy WallMay 18, 2009 7:00 am 
Sylvain ZUNINO [GMAIL]May 18, 2009 7:46 am 
Sylvain ZUNINO [GMAIL]May 18, 2009 9:56 am 
Timothy WallMay 18, 2009 10:04 am 
Sylvain ZUNINO [GMAIL]May 18, 2009 10:14 am 
Timothy WallMay 18, 2009 11:00 am 
Sylvain ZUNINO [GMAIL]May 18, 2009 11:43 am 
Sylvain ZUNINO [GMAIL]May 18, 2009 11:50 am 
Timothy WallMay 18, 2009 12:02 pm 
Sylvain ZUNINO [GMAIL]May 18, 2009 12:34 pm 
Timothy WallMay 18, 2009 12:37 pm 
Sylvain ZUNINO [GMAIL]May 19, 2009 12:33 am 
Timothy WallMay 19, 2009 1:27 am 
Sylvain ZUNINO [GMAIL]May 19, 2009 1:35 am 
Timothy WallMay 19, 2009 2:18 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] Crash JVM call function many timesActions...
From:Sylvain ZUNINO [GMAIL] (sylv@gmail.com)
Date:May 18, 2009 11:43:44 am
List:net.java.dev.jna.users

finally I remove Native.setProteced(true); in my implementation and it works ....

Thank's for your help

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 ???