Wrapping C/C++ inside Java

前端 未结 8 1488
Happy的楠姐
Happy的楠姐 2021-02-07 09:24

I develop applications/programs in C/C++. I am more versed in these two languages and love being a C++ developer. I am wondering how to create a Java program that contains all m

8条回答
  •  梦谈多话
    2021-02-07 09:30

    You can write C++ code through JNI but there isn't a direct mapping from C++ classes to Java classes. I've used JNI to fix problems found in the android SDK (specifically, an incredibly slow FloatBuffer.put implementation) and I may end up using it for some performance critical areas. My advice would be to be use it sparingly and in a duck in, do the performance critical stuff and leave, without doing any memory allocation if you can help it. Also, don't forget to measure your code to see if it really is faster.

    Out of interest, what platform are you developing for? The only platform where it would make sense to wrap a lot of C++ code in a light java layer would be Android - on other platforms, just compile in C++ and have done with it.

提交回复
热议问题