四、JNA技术解密:
JNA是建立在JNI技术基础之上的一个Java类库,它使您可以方便地使用java直接访问动态链接库中的函数。
原来使用JNI,你必须手工用C写一个动态链接库,在C语言中映射Java的数据类型。
JNA中,它提供了一个动态的C语言编写的转发器,可以自动实现Java和C的数据类型映射。你不再需要编写C动态链接库。
当然,这也意味着,使用JNA技术比使用JNI技术调用动态链接库会有些微的性能损失。可能速度会降低几倍。但影响不大。
Java—C和操作系统数据类型的对应表
Java Type |
C Type |
Native Representation |
boolean |
int |
32-bit integer (customizable) |
byte |
char |
8-bit integer |
char |
wchar_t |
platform-dependent |
short |
short |
16-bit integer |
int |
int |
32-bit integer |
long |
long long, __int64 |
64-bit integer |
float |
float |
32-bit floating point |
double |
double |
64-bit floating point |