In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article shows you how to dynamically register native functions, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.
Java JNI is a way to statically register native functions. Its disadvantage is that for every java that declares a native function, it needs to generate .h, and then make it a link library. Relatively cumbersome.
In fact, the one-to-one correspondence between java native function and JNI function can be understood as the relationship between function and function pointer, so there is a way to register function dynamically.
A JNINativeMethod structure used in Andoird also holds this association, that is, Andorid uses an array of mapping tables for Java and C functions, in which the parameters and return values of the function are described. The array is of type JNINativeMethod and is defined as follows:
Typedef struct {
Const char* name; / / native function name
Const char* signature; / / native function signature, mainly including function parameter type and return value
Void*fnPtr; / / function pointer to create an association
} JNINativeMethod
The first variable, name, is the name of the function in Java.
The second variable, signature, uses a string to describe the parameters and return values of the function.
The third variable, fnPtr, is the function pointer to the C function.
One of the more difficult to understand is the second parameter, such as
"() V"
"(II) V"
"(Ljava/lang/String;Ljava/lang/String;) V"
In fact, these characters correspond to the parameter types of the function one by one.
The character in "()" represents the parameter, followed by the return value. For example, "() V" means void Func ()
"(II) V" means void Func (int, int)
The specific correspondence of each character is as follows
Character Java type C type
V void void
Z jboolean boolean
I jint int
J jlong long
D jdouble double
F jfloat float
B jbyte byte
C jchar char
S jshort short
The array starts with "[" and is represented by two characters.
[I jintArray int []
[F jfloatArray float []
[B jbyteArray byte []
[C jcharArray char []
[S jshortArray short []
[D jdoubleArraydouble []
[J jlongArray long []
[Z jbooleanArrayboolean []
The above are all basic types. If the argument to the Java function is class, it starts with "L" and ends with ";" with packages and class names separated by "/". The parameter of the corresponding C function name is jobject. One exception is the String class, whose corresponding class is jstring
Ljava/lang/String;Stringjstring
Ljava/net/Socket;Socketjobject
If the JAVA function is in an embedded class, use $as the delimiter between the class names.
For example, "(Ljava/lang/String;Landroid/os/FileUtils$FileStatus;) Z"
The above is how to register native functions dynamically. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.