Skip to main content

JNI how get values updated to int and double fields



How do two values I pass into my JNI tossed down to C then C does its changes and updates the values. How do I get those two values(maxPower, index) and see then in Java? They always come back as zero.







JNIEXPORT jdouble JNICALL Java_com_TV (

JNIEnv* env, jobject obj, jdouble maxPower, jint index)

{

jdouble result = 0;



result = Feature_TV(2, &maxPower, &index );



return result;

}







// here is the c function it calls it actually does more than this but for // demo it should return result 60 and maxPower and index should be -5.0 and -2..







double Feature_TV(double * maxPwr, int * maxPwrIdx ) {



*maxPwr = -5.0;

*maxPwrIdx = -2;



/// do something



return 60;

}




Comments

  1. There is no way to modify the variables that are passed to Java_com_TV because C is pass-by-value, just like Java. When you call Feature_TV and pass the addresses of maxPower and index, the addresses are of the local variables in Java_com_TV and no outside effect can be seen.

    To do what you want to do you could either


    make com.TV accept an object that has maxPower and index as fields, and modify the fields from JNI, or
    make it return such an object, and create the object and set the fields in JNI.

    ReplyDelete

Post a Comment

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.