📜  比较 Android NDK 和 RenderScript

📅  最后修改于: 2022-05-13 01:58:10.790000             🧑  作者: Mango

比较 Android NDK 和 RenderScript

本文将比较 Android NDK 与 RenderScript。 NDK 和 RenderScript 的目标都是提高应用程序性能。每个都有优点和缺点。

NDK 和 RenderScript 有什么区别?

众所周知,NDK 和 RenderScript 的共同目标是提高应用程序性能。但是,每个都有自己的优点和缺点。

NDK

RenderScript

The Native Development Kit (NDK), according to official documentation, is a suite of tools that allows you to use C and C++ code in your Android app. You may use it to build from your own source code or to utilize prebuilt libraries that are already available.RenderScript is a framework for executing computationally demanding operations on Android with high speed. RenderScript is mostly used for data-parallel processing, although it can also assist serial computationally heavy tasks.
The NDK complicates the development process by pushing the limits to a single channel.The RenderScript runtime will parallelize the work on available processors on a device, balancing the load.

Can be beneficial in the following situations:

  • Use your C or C++ libraries again.
  • Get the most out of a gadget by using it for computationally intensive activities such as games or physics simulations.

Can be beneficial in:

  • Image processing
  • Computational photography
  • Computer vision applications.
The NDK is better suited for high-performance OpenGL programs or games that require access to additional graphics SDK capabilities or third-party libraries.RenderScript setup and configuration are simple for pure computational usage, and the results may surpass equivalent solutions that use the NDK, with fewer coding required programs.
The NDK enables developers to create C or C++ code and communicate with their Android applications using the Java Native Interface (JNI) mechanism. Standard libraries are provided, and existing C/C++ programs may typically be converted with few modifications. Furthermore, C++ is not that dissimilar to Java, and many engineers are fluent in both languages.RenderScript provides an alternative method, combining C99 syntax (standard C from 1999; the current standard is C11, which was introduced in 2011) with new APIs that are eventually converted to native code. While this syntax is generally known, using this system requires some study because the APIs are not.
Code developed using the NDK must be compiled ahead of time for each target native platform. The NDK components of the app will not operate properly if the app is launched on a platform with an unsupported architecture. RenderScript compiles on your development workstation first, then on the target device, resulting in more efficient native binary code.RenderScript now produces code that runs solely on the primary CPU and automatically generates code that can take advantage of extra cores when they are available on the target device. However, there are plans to make it operate on the GPU in the future. This is comparable to the CUDA and OpenCL platforms.

Advantages:

  1. C++ code can be used on both Android and iOS, but RenderScript code can only be used on Android.
  2. Debugging is simpler.
  3. Integration with other C++ libraries is simple.
  4. There are no API restrictions, but Android only gives a few API for RenderScript.

Advantages:

  1. RenderScript may leverage CPU, GPU, or other processing units, which results in significant speed gains.
  2. Android has architectural independence across x86, mips, and intel architectures.
  3. Parallel execution is easier.
  4. Image processing, computational photography, 3D rendering, and computer vision are the best applications.

结论

就这样,关于Android NDK和Render Script的讨论到此结束,希望本文对理解有帮助。使用 NDK、RenderScript 还是坚持使用Java完全取决于您,开发人员。这是一个具有重大影响的应用程序设计决策——它会影响您选择的编程语言、您的应用程序可以在哪些设备上运行以及您的源项目的维护难度。