指向未签名char *的JNA指针 [英] JNA pointer to unsigned char*

查看:158
本文介绍了指向未签名char *的JNA指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字节数组,我想使用JNA将其传递给C函数. 但是,我只发现了使用新内存分配指针并使用写功能复制数组数据的示例,但是对我来说这是不可接受的,因为我有大量数据.

I have an array of bytes and I want to pass it to C function using JNA. However I only found examples which allocated a pointer using new Memory and used write function to copy array data but for me is not acceptable because I have big block of data.

是否可以将我的Java数组直接传递到c库?

Is there a possibility just to pass my Java array directly to c library ?

我想做这样的事情:

MyLib lib = Native.loadLibrary("test");
Pointer p = myByteArray; //I want to make it possible
lib.someFunction(p);

推荐答案

将原始数组或Pointer传递给内存是等效的操作,即,您可以这样映射:

Passing a primitive array or a Pointer to memory are equivalent operations, i.e. you can map like this:

public interface MyLibrary extends Library {
    void someFunction(byte[] input);
    void someFunction(Pointer input);
}

这篇关于指向未签名char *的JNA指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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