将数组从JNI函数传递回而不复制它 [英] Pass an array back from a JNI function to without copying it

查看:116
本文介绍了将数组从JNI函数传递回而不复制它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用C ++使用JNI处理大量数据,但是我无法理解天气,函数SetArrayRegion将逐个元素复制一个数组元素,或者如果它只能将数据保留在原处并将其返回给调用java函数.

I am trying to use JNI to process large chunks of data using C++ however I am having trouble understanding weather the function SetArrayRegion will duplicate an array element by element or if it can just leave the data in place and return it to the calling java function.

以下文档是我一直在阅读的文档,但仍不清楚发生了什么. http://download.oracle.com/javase /1.5.0/docs/guide/jni/spec/functions.html

The following documentation is where I have been reading about it but it is still unclear what is going on. http://download.oracle.com/javase/1.5.0/docs/guide/jni/spec/functions.html

谢谢您的帮助.

推荐答案

通常,当您通过JNI传递数据时,它将跨JNI边界复制.如果您想要一种有效的机制来将数据从本机空间传递到Java空间,那么您应该研究如何访问NIO直接字节缓冲区.这可以提供可以在本机代码和Java代码之间共享的一部分内存.查看 GetDirectBufferAddress

Generally when you pass data via JNI it will be copied across the JNI boundary. If you want an efficient mechanism for passing data from native space up to Java space then you should look at how to access NIO direct byte buffers. This can provide a section of memory that can be shared between native code and Java code. Look at GetDirectBufferAddress.

这篇关于将数组从JNI函数传递回而不复制它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆