java - 与 Java 相比,Android C 是否具有更好的性能?

标签 java android c jvm

<分区>

在 Android 上 NDK您可以阅读的网站:

The Android NDK is a companion tool to the Android SDK that lets you build performance-critical portions of your apps in native code.

...

If you write native code, your applications are still packaged into an .apk file and they still run inside of a virtual machine on the device

...

Using native code does not result in an automatic performance increase, but always increases application complexity.

如果 C 也被编译为 VM 代码,那么如何使用 C 和 NDK 提高性能?您可以绕过 API,或者 C 编译成更优化的代码,或者什么?

或者它只是“开发加速”,所以如果你有一些 C 代码,你不必将它移植到 Java?

编辑:

问是否“Java 比 C 慢”。我的考虑是,如果C是用gcc编译的,那么可移植性是如何解决的(不过这是第二个问题,在后台)

What are the portability implications of using the NDK?

最佳答案

NDK 允许您添加到应用中的 C 代码不会编译成 VM 代码。它使用 gcc 和链接编译为共享库,可以通过 JNI 加载和链接。到 java 。因此,在编写 Java 代码时,您可以通过用 C 编写而不是依赖 JVM 优化来获得性能。

关于java - 与 Java 相比,Android C 是否具有更好的性能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8227591/

相关文章:

c - 关键部分中使用的资源是否需要 volatile?

java - 在另一个类中创建我的 Gui 的对象时,框架加载但内部没有任何内容

java - 构建 AAB 时出错 - Flutter (Android) - 完整性检查失败 : java. security.NoSuchAlgorithmException:算法 HmacPBESHA256 不可用

Android:在xml中创建一个可变模块

c - 在 C 中获得大约 20-30 位的精度

c - 为什么我的代码输出随机数,即使它们只是计数?

java - 可执行 jar 运行速度比 Eclipse 慢

java - 如果 ChangeListener 内焦点发生更改,DatePicker 不会提交值

java - 使用 Hibernate 延迟获取单列(类属性)

android - alarmmanager 2次