JNA以结构体数组为参数进行调用:
////// C++
// student 结构体定义
typedef struct
{
int age;
char name[20];
}Student;
// 修改java对象的属性值
JNAAPI bool changeObjs(Student stu[],int size)
{
for(int i=0;i<size;i++)
{
stu[i].age*=10;
strcpy(stu[i].name,"wokettas");
}
return true;
}
/////// Java
// JNA调用方法
Student[] stus=new Students[2];
Student s1=new Student();
Student s2=new Student();
s1.age=1;
s1.name=Arrays.copyOf("k1".getBytes(), 20);
s2.age=2;
s2.name=Arrays.copyOf("k2".getBytes(),20);
stus[0]=s1; //数组赋值
stus[1]=s2;
Gui.gui.changeObjs(stus, stus.length);
运行报错:
Structure array elements must use contiguous memory (bad backing address at Structure array index 1)
结构体数组必须使用连续的内存区域, 上例s1,s2都是new出来的新对象,不可能连续; 也就是说传统方式的初始化数组不能解决, 查询JNA api发现里面提供了:
toArray
public Structure[] toArray(int size)
Returns a view of this structure's memory as an array of structures. Note that this Structure
must have a public, no-arg constructor. If the structure is currently using a Memory
backing, the memory will be resized to fit the entire array.
修改后的代码:
// 测试对象数组
Student student=new Student();
Student[] stus=(Student[]) student.toArray(2); //分配大小为2的结构体数组
stus[0].age=1;
stus[0].name=Arrays.copyOf("k1".getBytes(), 20);
stus[1].age=2;
stus[1].name=Arrays.copyOf("k2".getBytes(),20);
Gui.gui.changeObjs(stus, stus.length);
分享到:
相关推荐
Contiguous Memory Allocator for DMA mapping framework.
PV guests under Xen are running in an non-contiguous memory architecture.
Contiguous Memory Allocator for ppc KVM hash pagetable based on CMA for DMA mapping framework.
contiguous()方法
Finding Maximum Contiguous Subsequence Sum using divide-and-conquer approach
Contiguous Memory Allocator for Linux v2.13.6.
drm gem CMA (contiguous memory allocator) helper functions.
Contiguous_List.cpp
pytorch pytorch_contiguous() 函数
memory comes in 64Mb contiguous chunks which are either present or not.
linux cma学习PPT,Linux Contiguous Memory Allocator的相关知识,很好的PPT。
连续内存分配使用 Python 的连续内存分配器类 by I_Jemin ijemin.com 使用 Python 的连续内存分配器模拟类。 不包括接口或测试类。 您可以将 MemoryManager 类导入到您的界面类或 GUI 类中。
– run_addr = address (运行时地址,address at run-time) – load_addr = address (在复制到运行地址前,初始地址在ROM中(initial address)) – ordered (以group中定义的排序方式来将sections定位到地址...
Directory Structure Fil S t M ti File System Mounting File Sharing g Protection Southeast University 10.2 Operating System Concepts File Concept e Co cept Contig o s logical address space ...
Consider:class Char_vec {intsz ;charelement [1];...Define new_char_vec() to allocate contiguous memory for a Char_vec object so that the elements can be indexed through element as shown.
RUNS = CONTIGUOUS(A,NUM) 返回向量 A 中元素 NUM 的连续运行的开始和停止索引。A 和 NUM 可以是整数或字符的向量。 输出 RUNS 是一个 2 列元胞数组,其中第一列的第 i 行包含来自向量 NUM 的第 i 个值,第二列的第 ...
这个文档的质量相当高,不过是纯英文的,但是,我保证你看过之后,肯定会认为这个文档写得实在太好了。
数据库 等待事件Db file sequential read...This call differs from a scattered read, because a sequential read is reading data into contiguous memory space. A sequential read is usually a single-block read.
elements to one side of the array 6. Find the Union and Intersection of the two sorted arrays. 7. Write a program to cyclically rotate an array by one. 8. find Largest sum contiguous Subarray [V. IMP]...
You can see this extra value if you use DBCC PAGE to look at the actual index rows the section on indexes internal. . Finding Rows in a Clustered Index The Leaf Level of a Clustered Index ...