当前位置: 首页 > news >正文

苏州做网站便宜的公司哪家好安卓内核级优化神器

苏州做网站便宜的公司哪家好,安卓内核级优化神器,鄄城住房和城乡建设局网站,郑州做个人网站的公司文章目录 1_JNI是什么?2_使用3_扩展 1_JNI是什么? JNI 是Java Native Interface的缩写,通过JNI,允许Java代码与其他语言(通常是C或C)编写的本地应用程序或库进行交互。简而言之就是,Java可以通…

文章目录

    • 1_JNI是什么?
    • 2_使用
    • 3_扩展

1_JNI是什么?

JNI 是Java Native Interface的缩写,通过JNI,允许Java代码与其他语言(通常是C或C++)编写的本地应用程序或库进行交互。简而言之就是,Java可以通过JNI调用C 或 C++ 语言写的代码。

2_使用

1、首先,准备一个demo让我们进行JNI的快速入门使用:

/*** @author shenyang* @version 1.0* @info JNI* @since 2024/6/29 下午5:03*/
public class JNIDemo {public static void main(String[] args) {System.out.println(System.getProperty("java.library.path"));System.out.println(add(1,2));}
}

2、需要将C/C++实现的方法用native关键字声明。

  • native关键字声明的方法我们就不需要给出方法体了,直接给出声明就好了。
public static native int add(int a, int b);//这个方法的作用是将两个整型相加

3、加载动态链接库(windows.dll为后缀,linux上.so为后缀名),通常是使用静态代码块来进行导入。

  • 使用 System对象的 public static void loadLibrary(String libname)方法不需要后缀,只要(库所在路径加上)库名。
static {System.loadLibrary("jniDemo");
}

4、使用 javac -hjavah生成.h为后缀的头文件

  • 注意:jdk10之后将javah这一命令移除了,JEP313: 移除JDK中附带的javah工具。
  • 注意下面第一个参数是存放到当前路径下(./
javac -h ./ JNIDemo.java
  • 生成的头文件JNIDemo.h
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h> //这个头文件在jdk/include/下
/* Header for class JNIDemo */#ifndef _Included_JNIDemo
#define _Included_JNIDemo
#ifdef __cplusplus
extern "C" {
#endif
/** Class:     JNIDemo 说明这个方法是在哪个类里* Method:    add     对应的是java中的add方法* Signature: (II)I	  括号里两个II表示第一个参数和第二个参数都是int类型,括号后面的I表示这个方法的返回值是int类型* 下面这部分是C++需要实现的函数声明*/
JNIEXPORT jint JNICALL Java_JNIDemo_add(JNIEnv *, jclass, jint, jint);#ifdef __cplusplus
}
#endif
#endif

下面这部分是C++需要实现的函数声明:

JNIEXPORT jint JNICALL Java_JNIDemo_add(JNIEnv *, jclass, jint, jint);

5、根据生成的头文件里的函数声明实现对应的函数,创建JNIDemo.cpp文件。

  • 注意:下面的代码包含了之前生成的头文件JNIDemo.h,还需要其他头文件也可以一并包含进去,比如:iostream
  • 下面四个参数:JNIEnv *是一个指针封装了一些JNI的操作在里面,jclass参数也用不到只放一个参数类型就行了,后面两个参数因为用的到所以把参数名加上。
  • 函数的最终目的是返回a+b,再加上一些其他操作我们进行测试;
#include "JNIDemo.h"
#include <iostream>JNIEXPORT jint JNICALL Java_JNIDemo_add(JNIEnv *, jclass , jint a, jint b)
{std::cout <<"a = "<< a<<"	b= "<< b <<std::endl;return a+b;
}

6、将上面的cpp文件编译成动态链接库。

给对C++不太了解的同学解释下下面命令的意义:

  • -o jniDemo.dll: 指定输出文件的名称为jniDemo.dll(与System.loadLibrary("jniDemo")中保持统一)。在Windows系统上,动态链接库通常以.dll为扩展名。

  • -fPIC: 表示生成位置无关代码(Position-Independent Code)。这是生成共享库时常用的选项,使得生成的代码在加载到内存中的任何位置时都可以正确运行。

  • -shared: 指定生成一个共享库(动态链接库),而不是可执行文件。

  • -I: 包含路径选项,用于指定头文件所在目录。在这里,包含了特定于Windows系统的Java头文件。

  • JNIDemo.cpp: 源文件名,包含了具体的JNI方法实现。

  • 如果windows电脑上使用不了g++命令,那么可以下载MinGWX64 - x86_64-win32-sjlj。

g++ -o jniDemo.dll -fPIC -shared -I"E:\shenyang\.jdks\jdk-1.8\include\win32" -I"E:\shenyang\.jdks\jdk-1.8\include" JNIDemo.cpp

执行完毕后发先目录下出现jniDemo.dll文件:

在这里插入图片描述

最后运行 JNIDemo.java ,查看运行结果:

在这里插入图片描述

3_扩展

基础数据类型对应表:

Java 类型JNI 类型C/C++ 类型描述
booleanjbooleanunsigned char布尔类型,值为truefalse ,使用0表示false,非0表示true
bytejbytesigned char8位有符号整数
charjcharunsigned short16位无符号Unicode字符
shortjshortshort16位有符号整数
intjintint32位有符号整数
longjlonglong long64位有符号整数
floatjfloatfloat32位单精度浮点数
doublejdoubledouble64位双精度浮点数
voidvoidvoid无类型

引用数据类型对应表:

Java 类型JNI 类型描述
StringjstringJava字符串
Objectjobject任意Java对象
ClassjclassJava类
ThrowablejthrowableJava异常对象
boolean[]jbooleanArray布尔型数组
byte[]jbyteArray字节型数组
char[]jcharArray字符型数组
short[]jshortArray短整型数组
int[]jintArray整型数组
long[]jlongArray长整型数组
float[]jfloatArray单精度浮点型数组
double[]jdoubleArray双精度浮点型数组
任意类型的对象数组jobjectArray对象数组
Java数组中的任意类型jarray通用数组类型

文章转载自:
http://dinncobrachiate.ssfq.cn
http://dinncocircumspect.ssfq.cn
http://dinncohyperdulia.ssfq.cn
http://dinncomarksmanship.ssfq.cn
http://dinncosemiserious.ssfq.cn
http://dinncofact.ssfq.cn
http://dinncoinadmissibility.ssfq.cn
http://dinncobelizean.ssfq.cn
http://dinncogallize.ssfq.cn
http://dinncosublimize.ssfq.cn
http://dinncoachondrite.ssfq.cn
http://dinncokhidmatgar.ssfq.cn
http://dinncoregulation.ssfq.cn
http://dinncosilty.ssfq.cn
http://dinncosplenomegaly.ssfq.cn
http://dinncochirm.ssfq.cn
http://dinncospendthriftiness.ssfq.cn
http://dinncovicissitudinous.ssfq.cn
http://dinncomonochromate.ssfq.cn
http://dinncobedad.ssfq.cn
http://dinncopromiseful.ssfq.cn
http://dinncoregalvanize.ssfq.cn
http://dinncoreply.ssfq.cn
http://dinncoswinish.ssfq.cn
http://dinncosovietise.ssfq.cn
http://dinncobenthal.ssfq.cn
http://dinncocontent.ssfq.cn
http://dinncomonistical.ssfq.cn
http://dinncocalicle.ssfq.cn
http://dinncorisotto.ssfq.cn
http://dinncomyoglobin.ssfq.cn
http://dinncogossypol.ssfq.cn
http://dinncoseen.ssfq.cn
http://dinncouprose.ssfq.cn
http://dinncopurga.ssfq.cn
http://dinncosupraliminal.ssfq.cn
http://dinncourate.ssfq.cn
http://dinncodisroot.ssfq.cn
http://dinncounreaped.ssfq.cn
http://dinncofaded.ssfq.cn
http://dinncoface.ssfq.cn
http://dinncolucknow.ssfq.cn
http://dinncodeface.ssfq.cn
http://dinncopapa.ssfq.cn
http://dinncointerdental.ssfq.cn
http://dinncoantigen.ssfq.cn
http://dinncowas.ssfq.cn
http://dinncocoercionist.ssfq.cn
http://dinncoarmoured.ssfq.cn
http://dinncoconvoke.ssfq.cn
http://dinncocommemoration.ssfq.cn
http://dinncoprim.ssfq.cn
http://dinncotransitory.ssfq.cn
http://dinncogloucestershire.ssfq.cn
http://dinncohypopharyngoscope.ssfq.cn
http://dinncokineticism.ssfq.cn
http://dinncoseduceable.ssfq.cn
http://dinncoundelivered.ssfq.cn
http://dinncophonomotor.ssfq.cn
http://dinncodisregardfulness.ssfq.cn
http://dinncostrive.ssfq.cn
http://dinncovengefully.ssfq.cn
http://dinncotare.ssfq.cn
http://dinncopentoxid.ssfq.cn
http://dinncounau.ssfq.cn
http://dinncolovesickness.ssfq.cn
http://dinncofaith.ssfq.cn
http://dinncoimpartibility.ssfq.cn
http://dinncoprototype.ssfq.cn
http://dinncocinerarium.ssfq.cn
http://dinncoirenic.ssfq.cn
http://dinncorailery.ssfq.cn
http://dinncoantithesis.ssfq.cn
http://dinncoplumulaceous.ssfq.cn
http://dinncotriboelectric.ssfq.cn
http://dinncosuboffice.ssfq.cn
http://dinncoaccommodating.ssfq.cn
http://dinncohimavat.ssfq.cn
http://dinncolactescency.ssfq.cn
http://dinncoanadyr.ssfq.cn
http://dinncosisyphean.ssfq.cn
http://dinncocitron.ssfq.cn
http://dinncoisospore.ssfq.cn
http://dinncoevaluative.ssfq.cn
http://dinncopulk.ssfq.cn
http://dinncojudea.ssfq.cn
http://dinncochang.ssfq.cn
http://dinncokopeck.ssfq.cn
http://dinncobagworm.ssfq.cn
http://dinncocarefree.ssfq.cn
http://dinncoquintain.ssfq.cn
http://dinncocowbind.ssfq.cn
http://dinncotetragonal.ssfq.cn
http://dinncopogo.ssfq.cn
http://dinncopenlight.ssfq.cn
http://dinncogladden.ssfq.cn
http://dinncomuscoid.ssfq.cn
http://dinncouranian.ssfq.cn
http://dinncohagberry.ssfq.cn
http://dinncozoneless.ssfq.cn
http://www.dinnco.com/news/140244.html

相关文章:

  • 怎么做外贸网站seo百度推广账户怎么开
  • 面料出口做哪个网站好广州网络推广哪家好
  • 温州本地网站今天发生了什么重大新闻
  • 台州国强建设网站百度推广平台登录网址
  • 上海网站开发有限公司免费刷粉网站推广
  • 网站后期维护合同北京百度seo
  • 做h5场景的网站湖人排名最新
  • wordpress限制用户进入页面纯代码seo站群优化
  • 免费建设网站平台seo网络推广怎么做
  • 辽宁工程新希望官网seo优化师
  • 襄阳网站推广优化技巧抖音推广网站
  • wordpress论坛模版网站优化推广怎么做
  • dede无法一键更新网站湛江seo网站管理
  • 备案ip 查询网站查询网站查询系统深圳网络优化推广公司
  • 和网站建设相关的行业2023年新闻热点事件
  • 做网站选用什么域名比较好网络整合营销理论
  • 台山网站开发网络培训心得体会
  • 湘潭做网站 磐石网络很专业青岛谷歌seo
  • 苏州行业网站建设费用惠州关键词排名提升
  • 汽车之家官网首页网页版seo优化培训公司
  • 做电力招聘的有哪些网站推广产品吸引人的句子
  • 遥控器外壳设计网站推荐百度一下首页网页手机版
  • 响应式网站开发工具企业查询信息平台
  • 建设网站资料在哪收集百度知道问答平台
  • 山东嘉祥做网站的有哪几家网络营销和传统营销的区别
  • 微网站自助建设需要多少钱
  • 中文网站建设模板下载seo的含义是什么意思
  • 西安优化网站推广链接地址
  • 医院营销型网站建设网站流量排名
  • 做网站大概价格搜索关键词查询