How C++ can call Java through JNI
So this is how it should be done. This will be useful in Linux for when both the C++/C generated code from Maltba/ Simulink may need to call any front Java generated by Matlab Guide which would be deployed to an executable deployed Java JAR.
On my core i7, the results are the following:Java called from Java: 14 nanoseconds/iteration Java called from C++: 23 nanoseconds/iteration C++ 100% native: 2 nanoseconds/iteration
Each C++ to Java call through JNI has an overhead of 9 to 10 ns. For small functions such as in this benchmark, this overhead is an overkill. So this kind of integration should not be considered for high frequency, low latency function calls. But many JNI applications are about integrating high level Java components or interfaces. In this case, the JNI overhead is negligible compared to the tremendous benefit of the easy integration.
NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!