• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Need explanation on how native method works.

 
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.
 
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 ]
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic