This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Need explanation on how native method works.  RSS feed

 
Aji Prasetyo
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using native method to transfer the data, which is a 2-dimentional int array named localArrayCopy[769][2].

through browsing I found a code to call java method from C++ in order to send the data from C++ to java, so I just copy-paste it.

Could somebody tell me about the mechanism of the following native method program. It suppose to call the java function but I don't know how it works.

Thank you so much.

 
Aji Prasetyo
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know its been a while and nobody catch this thread.

I know everybody been busy, so I think I'll just simplifies the question.
Actually I've been wondering about the "boolean lock" parameter in the native method.





Why is it needed to call a void method and what exactly is MonitorEnter(lock)?

Thank you so much beforehand.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will not be able to write working native methods by "copy and paste programming". You will need to understand what is going on, and code each line carefully.

Have you read the JNI specification? You need to do so. This will answer your questions about what various functions do. If you don't find the specification comprehensible, then you don't have the necessary background to do native method programming, and you'll need to learn more about C code etc.

You CallVoidMethod(), because the return type of the Java method sendArrayResults() is void. Well, it had better be, otherwise your code is wrong.

MonitorEnter() and MonitorExit() do what entering and exiting a synchronized block do in Java. Whether you need to do that, I can't say - it depends on what your Java code and your native code do.
[ September 24, 2007: Message edited by: Peter Chase ]
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!