博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
15.2.2.4 传递整型数组
阅读量:2299 次
发布时间:2019-05-09

本文共 3227 字,大约阅读时间需要 10 分钟。

public class Sample2{        public native int[] intMethod();       public static void main(String[] args)      {         System.loadLibrary("Sample2");         Sample2 sample=new Sample2();           int[] nums=sample.intMethod();        for(int i=0;i
NewIntArray(10); for(; i<= 10; i++) env->SetIntArrayRegion( array, i-1, 1, &i); // 获取数组对象的元素个数 int len = env->GetArrayLength( array); // 获取数组中的所有元素 jboolean iscopy; jint* elems = env-> GetIntArrayElements(array, &iscopy); if(iscopy) printf("iscopy is true\n"); else printf("iscopy is false\n"); for(i=0; i
public class Sample2{        public native int[] intMethod();       public static void main(String[] args)      {         System.loadLibrary("Sample2");         Sample2 sample=new Sample2();           int[] nums=sample.intMethod();        for(int i=0;i
NewIntArray(10); for(; i<= 10; i++) env->SetIntArrayRegion( array, i-1, 1, &i); // 获取数组对象的元素个数 int len = env->GetArrayLength( array); // 获取数组中的所有元素 jboolean iscopy; jint* elems = env-> GetIntArrayElements(array, &iscopy); if(iscopy) printf("iscopy is true\n"); else printf("iscopy is false\n"); for(i=0; i
ReleaseIntArrayElements(array,elems,0);//释放~~~ // 对于最后一个参数(如果指针指向的数组为副本时,否则该参数不起作用) // 0 copy back the content and free the elems buffer // JNI_COMMIT copy back the content but do not free the elems buffer // JNI_ABORT free the buffer without copying back the possible changes if(iscopy) printf("iscopy is true,copy back the content and free the elems buffer\n");return array;}*//*iscopy is trueELEMENT 0 IS 1ELEMENT 1 IS 2ELEMENT 2 IS 3ELEMENT 3 IS 4ELEMENT 4 IS 5ELEMENT 5 IS 6ELEMENT 6 IS 7ELEMENT 7 IS 8ELEMENT 8 IS 9ELEMENT 9 IS 10iscopy is true,copy back the content and free the elems buffer234567891011请按任意键继续. . .*/
// Sample2.cpp : 定义 DLL 应用程序的导出函数。//#include "stdafx.h"#include "..\Sample2.h"JNIEXPORT jintArray JNICALL Java_Sample2_intMethod  (JNIEnv *env, jobject obj){	  jint i = 1;            jintArray  array;//定义数组对象           array = env-> NewIntArray(10);           for(; i<= 10; i++)               env->SetIntArrayRegion( array, i-1, 1, &i);          /* 获取数组对象的元素个数 */      int len = env->GetArrayLength( array);       /* 获取数组中的所有元素 */	  jboolean iscopy;      //jint* elems = env-> GetIntArrayElements(array, &iscopy);	  jint* elems = (jint*)env-> GetPrimitiveArrayCritical(array, &iscopy);	  if(iscopy)		  printf("iscopy is true\n");	  else		  printf("iscopy is false\n");     for(i=0; i
ReleasePrimitiveArrayCritical(array,elems,0); //env->ReleaseIntArrayElements(array,elems,0);//释放~~~ // 对于最后一个参数(如果指针指向的数组为副本时,否则该参数不起作用) // 0 copy back the content and free the elems buffer // JNI_COMMIT copy back the content but do not free the elems buffer // JNI_ABORT free the buffer without copying back the possible changes if(iscopy) printf("iscopy is true,copy back the content and free the elems buffer\n"); else printf("iscopy is false,理论上副本elems的改变直接导致array的改变!\n");return array;}

转载地址:http://kukib.baihongyu.com/

你可能感兴趣的文章
java虚拟机_jvm_java内存区域
查看>>
ICE框架【源于.NET、CORBA及WEB SERVICE这些中间件的不足】-----ICE简单介绍及使用示例
查看>>
mysql远程连接命令
查看>>
聚焦爬虫:定向抓取系统的实现方法
查看>>
网络爬虫基本原理二
查看>>
网络爬虫基本原理(一)
查看>>
hadoop edits 文件损坏修复办法
查看>>
【源码】Hadoop 2.x中fsimage和edits合并实现
查看>>
MySQL配置文件my.cnf参数优化和中文详解
查看>>
对MySQL配置参数 my.ini/my.cnf的详细解析
查看>>
JDBC连接MySQL【各参数详解】
查看>>
完整java开发中JDBC连接mysql或者其他数据库代码和步骤
查看>>
mysql读写分离的完整配置【centos6.5-mini版操作系统中mysql数据库的操作日志以及创建的数据库和表均在/var/lib/mysql此目录下,yum源在/var/lib/yum下】
查看>>
未测试---- mysql+spring+mybatis实现数据库读写分离[代码配置]
查看>>
【未测试】使用mysql-proxy 快速实现mysql 集群 读写分离
查看>>
【对比mysql各种代理】mysql中间件研究(Atlas奇虎360,cobar阿里巴巴,TDDL淘宝分布式数据层)
查看>>
【未测试】采用Atlas+Keepalived实现MySQL读写分离、读负载均衡
查看>>
【已测试】Java+MySQL实现网络爬虫程序
查看>>
数据挖掘工程师笔试及答案整理
查看>>
数据挖掘方法案例介绍
查看>>