Forums Register Login

Need explanation on how native method works.

+Pie Number of slices to send: Send
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.

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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 ]
Wink, wink, nudge, nudge, say no more, it's a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1028 times.
Similar Threads
JNI ( Java Native Interface)
chaning array contents in java native function
lingle
Exception in thread "AWT-EventQueue-1"
what's wrong with my program about JNI callback
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 22:36:48.