Win a copy of Functional Design and Architecture this week in the Functional programming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Need explanation on how native method works.

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic