【翻译练习】JNI Tips.

原文链接:http://developer.android.com/training/articles/perf-jni.html

JNI is the Java Native Interface.

JNIjava本地接口.

It defines a way for managed code (written in the Java programming language) to interact with native code (written in C/C++).

它定义一种方式去管理代码(java语言编写的代码)与本地代码交互(c/c++写的代码)

It's vendor-neutral,has support for loading code from dynamic shared libraries, and while cumbersome at times is reasonably efficient.

(vendor-neutral不是太明白什么意思,按照字面意思是"中立的供应商"),支持从动态分享库中读取代码.虽然有些时候麻烦,但是是合理有效的.

If you're not already familiar with it,

如果你还没有熟悉它,

read through the Java Native Interface Specification to get a sense for how JNI works and what features are available.

通过阅读java本地接口说明去了解jni如何工作和有什么可用的特性.

Some aspects of the interface aren't immediately obvious on first reading, so you may find the next few sections handy.

第一次阅读接口的一些方面不明显,不过你也许能在接下来的章节方便的获得(意思说下面章节会更加明显的表述jni接口的意思).

JavaVM and JNIEnv

JNI defines two key data structures, "JavaVM" and "JNIEnv".

JNI定义了2个关键的数据结构,javaVM和JNIEnv.

Both of these are essentially pointers to pointers to function tables.

这2种数据结构本质上是指向函数表的指针.

(In the C++ version, they're classes with a pointer to a function table and a member function for each JNI function that indirects through the table.)

(在C++版本中,它们是指向函数表的类然后一个成员函数间接地通过这张表对应每个JNI函数.)

The JavaVM provides the "invocation interface" functions,

JavaVM提供接口调用函数,

which allow you to create and destroy a JavaVM. In theory you can have multiple JavaVMs per process, but Android only allows one.

它允许你去创建和销毁一个javaVM,在理论上每个进程你可以有多个javaVM,但是Android只允许你有一个.

The JNIEnv provides most of the JNI functions. Your native functions all receive a JNIEnv as the first argument.

JNIEnv提供大多数的JNI函数,你的所有本地方法接收一个JNIEnv作为第一个参数.

The JNIEnv is used for thread-local storage. For this reason, you cannot share a JNIEnv between threads.

JNIEnv被用来给本地线程存储,因此,你不能在线程之间分享一个JNIEnv.

If a piece of code has no other way to get its JNIEnv,

如果一段代码没有其它方式获得它的JNIEnv,

you should share the JavaVM, and use GetEnv to discover the thread's JNIEnv. (Assuming it has one; see AttachCurrentThread below.)

你应该共享javaVM,然后使用GetEnv去发现这个线程JNIEnv(如果它有一个,看下面的AttachCurrentThread).

The C declarations of JNIEnv and JavaVM are different from the C++ declarations.

JNIEnv和JavaVM的C语言声明不同于C++的声明.

The "jni.h" include file provides different typedefs depending on whether it's included into C or C++.

jni.h头文件提供不同的类型定义依靠它是否包含进了(c或c++),

For this reason it's a bad idea to include JNIEnv arguments in header files included by both languages.

由于这个原因,它是

(Put another way: if your header file requires #ifdef __cplusplus, you may have to do some extra work if anything in that header refers to JNIEnv.)

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值