Jump to content
  • Advertisement
Sign in to follow this  
plywood

Java/C++ interface

This topic is 3779 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Given ===== Driver.java -> The driver with main() inside of it Widget.java -> A widget; to be stored on nodes in a tree Tree.cpp -> A C++ generic tree (multitree) Out of pure curiousity, is it possible for the Driver to create a whole lotta Widgets, and "pop" them onto the C++ tree? In other words, is it possible, under this scenario, for a Java program and C++ file to interact with each other on the same hardware/OS platform? If so, how? Else, why not? If more complicated to explain, indulge pour moi?

Share this post


Link to post
Share on other sites
Advertisement
Look into the JNI (Java Native Interface) , its quite horrible and clunky but it does allow you to execute and use native code from a java application.

Share this post


Link to post
Share on other sites
Quote:
Original post by SimonForsman
Look into the JNI (Java Native Interface) , its quite horrible and clunky but it does allow you to execute and use native code from a java application.


I second the JNI suggestion. Be warned though. JNI does not provide you the same robustness of standard Java that you are used to (exception handling, memory management etc). With JNI your C++ shared library will be linked in by the Java runtime machine. If there is a bug in your C++ code the JRE will not be forgiving. Memory leaks etc, will cause your JRE instance to core dump and you won't get any exceptions.

In other words don't count on the JRE to trap your C++ errors.

Share this post


Link to post
Share on other sites
Is there such a thing as "managed Java" in Visual Studios? That way, C++ modules and Java modules would all be compiled to the same intermediate object lang and should run smoothely together...?

Share this post


Link to post
Share on other sites
J# looks somewhat similar to Sun's Java, but does not run in the Java Virtual machine. It runs on the .NET platform.

JNI is the only way of using C/C++ code from within Java, but it's horrible to write code, is not cross-platform(Unless you compile your C++ code for the various platforms) and as said, unforgiving. It requires quite a lot of work to get basic C++ code working through JNI.

It's probably easier to re-write your C++ tree in Java.

Toolmaker

Share this post


Link to post
Share on other sites
Java is already "managed", so there is no point.

Have you considered the possibility that what you really want to do is just use C#? Or, as suggested, just write the tree in Java?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!