当前位置:网站首页>NDK beginner's study (1)
NDK beginner's study (1)
2022-07-07 14:11:00 【v_ three billion four hundred and eighty-three million six hund】
NDK Knowledge
1. Static registration .
Why should there be static registration , Because java Layer and the so The functions of the layer need to be mapped one by one , You can't get it wrong . Like the following .
public native String stringFromJNI();
How does that correspond .
Is the name of the function through jump , Very regular
Java_com_example_demonndk_MainActivity_stringFromJNI
yes java, Then the package name , Then the class name , Then the name . This is static registration .
JNIEnv env: Like jni Environment , It can be used to call c Layer of java. Or is it java Data type to c Data type of ,c Data to java Data conversion of data type .
The first parameter ,jobject: Like this The pointer , Know which place called so This function of layer
The second parameter ,jclass and jobject The distinction between : What should be declared Native When the method is static , Corresponding parameter jclass
, Because static methods don't rely on object instances , It depends on the class , So the parameter passed is a jclass
type . contrary , If it says Native Method time is not static method time , So the corresponding parameter is jobject
.
extern "C" JNIEXPORT jstring JNICALL Tell me so c By
The static registration function must be an export function JNIEXPORT
LOGD Output Head introduction #include <android/log.h> You can use __android_log_print(3,“moting”,__VA_ARGS__) 了 ;
Simplified can be logd
You can use it directly
logd(“hello”);
Create thread
pthread_t pthread;
//int pthread_create(pthread_t* __pthread_ptr, pthread_attr_t const* __attr, void* (*__start_routine)(void*), void*);
pthread_create(&pthread, nullptr,myThread, nullptr);
logd ("+++++++");
First there is a thread variable , Then create the thread .
Build a function above
void* myThread(void* a){
for (int i = 0; i <9; ++i) {
logd("myThread%d",i);
}
pthread_exit(0);
}
added pthread_join(pthread, nullptr) Is to execute in the thread first , Then execute the following code .
Send a number into the thread
pthread_t pthread;
int num=4;
//int pthread_create(pthread_t* __pthread_ptr, pthread_attr_t const* __attr, void* (*__start_routine)(void*), void*);
pthread_create(&pthread, nullptr, myThread, &num);
pthread_join(pthread, nullptr);
logd ("===============");
Pass it in with a pointer
void* myThread(void* a){
int *num= static_cast<int *>(a);
for (int i = 0; i <*num; ++i) {
logd("myThread%d",i);
}
pthread_exit(0);
}
Pass a structure into the thread
Create a thread
struct moting{
std::string name;
int age;
bool sex;
};
moting aaa;
aaa.name="moting";
aaa.age=3;
aaa.sex= true;
pthread_t pthread;
//int pthread_create(pthread_t* __pthread_ptr, pthread_attr_t const* __attr, void* (*__start_routine)(void*), void*);
pthread_create(&pthread, nullptr, myThread, &aaa);
pthread_join(pthread, nullptr);
logd ("===============");
Then pass the pointer .
c Language return values are rarely used ,
so Execution timing of various functions in
init -》 init_array-》 jni_onload
jnionload Rewriting of
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved){
JNIEnv *env= nullptr;
if (vm->GetEnv((void **)&env,JNI_VERSION_1_6)!=JNI_OK){
logd("getenv filed");
}
logd("JNI_Onload%p",env);
return JNI_VERSION_1_6;
}
One so There can be no JNI_ONLOAD, For example, create a new thread . Must return JNI Version of
JNIENV and JNIVm The difference between
JNIENV and JNIVm, Defines a global variable JavaVM* globalVM;
How to use env call vm, The first argument to the function is env
JavaVM *vm1;
env->GetJavaVM(&vm1);
globalVm=vm1;
vm1 It's worth it
perhaps JNI_OnLoad The first parameter of
- vm Get env
In the main route
if (vm->GetEnv((void **)&env,JNI_VERSION_1_6)!=JNI_OK){
logd("getenv filed");
}
In the sub thread
边栏推荐
- SSRF vulnerability file pseudo protocol [netding Cup 2018] fakebook1
- PostgreSQL array type, each splice
- [high frequency interview questions] difficulty 2.5/5, simple combination of DFS trie template level application questions
- 2022-7-6 初学redis(一)在 Linux 下下载安装并运行 redis
- Details of redis core data structure & new features of redis 6
- c#利用 TCP 协议建立连接
- FC连接数据库,一定要使用自定义域名才能在外面访问吗?
- Help tenants
- Social responsibility · value co creation, Zhongguancun network security and Information Industry Alliance dialogue, wechat entrepreneur Haitai Fangyuan, chairman Mr. Jiang Haizhou
- Advanced Mathematics - Chapter 8 differential calculus of multivariate functions 1
猜你喜欢

Flink | multi stream conversion

566. Reshaping the matrix

数据库系统概论-第一章绪论【概念模型、层次模型和三级模式(外模式、模式、内模式)】

How to check the ram and ROM usage of MCU through Keil

Help tenants

2022-7-6 Leetcode 977. Square of ordered array

2022-7-7 Leetcode 844. Compare strings with backspace

Dry goods | summarize the linkage use of those vulnerability tools

Wired network IP address of VMware shared host

Did login metamask
随机推荐
Is the spare money in your hand better to fry stocks or buy financial products?
Excusez - moi, l'exécution a été réussie lors de l'utilisation des données de puits SQL Flink à Kafka, mais il n'y a pas de nombre dans Kafka
Supply chain supply and demand estimation - [time series]
【日常训练--腾讯精选50】231. 2 的幂
FCOS3D label assignment
Navicat run SQL file import data incomplete or import failed
CSMA/CD 载波监听多点接入/碰撞检测协议
Laravel form builder uses
libSGM的horizontal_path_aggregation程序解读
社会责任·价值共创,中关村网络安全与信息化产业联盟对话网信企业家海泰方圆董事长姜海舟先生
請問,在使用flink sql sink數據到kafka的時候出現執行成功,但是kafka裏面沒有數
数据库系统概论-第一章绪论【概念模型、层次模型和三级模式(外模式、模式、内模式)】
Dry goods | summarize the linkage use of those vulnerability tools
股票开户首选,炒股交易开户佣金最低网上开户安全吗
SAKT方法部分介绍
Excuse me, I have three partitions in Kafka, and the flinksql task has written the join operation. How can I give the join operation alone
请问,在使用flink sql sink数据到kafka的时候出现执行成功,但是kafka里面没有数
.net core 关于redis的pipeline以及事务
Did login metamask
Realization of search box effect [daily question]