dw网站建设的心得体会,全屏背景网站如何做到自适应,临沂做网站哪家好,html5网页代码大全概述
项目需要用到 重采样算法#xff0c;JAVA 没有现成的#xff0c;只能通过 JNA 调用 C 的 DLL 实现#xff0c;JNA中#xff0c;它提供了一个动态的C语言编写的转发器#xff0c;可以自动实现Java和C的数据类型映射。不再需要编写C动态链接库。
实现需求
根据 一个…概述
项目需要用到 重采样算法JAVA 没有现成的只能通过 JNA 调用 C 的 DLL 实现JNA中它提供了一个动态的C语言编写的转发器可以自动实现Java和C的数据类型映射。不再需要编写C动态链接库。
实现需求
根据 一个数组数据算法根据数组生成多个相邻、相似的点。 案例 原始数组
[1,2,3,4,5,6,5,4,3,2,1]生成10个
[0.9975707933099867,2.0827107433705034,3.242373563930609,4.227786236390621,5.5680645300875815,5.6819573969217645,4.3206979326831965,3.3497212671714256,2.1727162369435766,1.115611206113079]生成20个
[1.0006736067597888,1.6136225699097613,2.0834240705596923,2.6000134251334908,3.2387063724897835,3.8026902204918467,4.232982835368568,4.801594298327119,5.562876758327512,6.0005892018875,5.686344251045411,4.934418414307205,4.317107510714494,3.885808545074988,3.3535095539415303,2.7104608356964937,2.167467521772395,1.7063151122165208,1.1234001156030098,0.45134020733353886]实现效果 实践
gredle 或 maven
版本有很多我用比较旧的若有不适可以用新的
implementation net.java.dev.jna:jna:4.0.0dependencygroupIdnet.java.dev.jna/groupIdartifactIdjna/artifactIdversion4.0.0/version
/dependencyNasalResamplingService
创建接口并声明方法方法名与DLL中方法名对应
public interface NasalResamplingService extends Library {/*** FileName NasalResamplingService.java* description 重采样算法* author lanys* date 2024-4-15 17:14:04* param srcArray 原始数组* param desArray 生成后的数组C赋值* param desArraySize 生成后数组长度* param srcArraySize 原始数据长度*/void myMatlabResample(double[] srcArray, double[] desArray, double desArraySize, double srcArraySize);}DllUtils
Slf4j
public class DllUtils {private NasalResamplingService instance;/** DLL 文件地址 */private final static String path 文件地址;public DllUtils() {instance (NasalResamplingService) Native.loadLibrary(path, NasalResamplingService.class);}public double[] resampling(double[] array, Integer extent) {TimeInterval timer DateUtil.timer();if (array ! null array.length 0) {double[] desArray null;if (extent ! null) {desArray new double[extent];} else {desArray new double[2000];}// 参数一原始数据数组// 参数二重采样数组// 参数三重采样数据长度固定2000// 参数四原始数据个数长度instance.myMatlabResample(array, desArray, desArray.length, array.length);log.info([DLL工具-重采样算法]DLL所需时间{} 毫秒, timer.interval());return desArray;}return null;}/*** FileName DllUtils.java* description 关闭DLL释放内存* author lanys* date 2024-4-16 11:11:59*/public void dispose() {try {log.info([DLL工具-释放DLL内存]);// 关闭DLL防止内存泄漏NativeLibrary instance NativeLibrary.getInstance(path);instance.dispose();}catch (Exception e){log.error([DLL工具-释放内存]数据异常,e);}}
}Controller自己写吧很简单
DllUtils dllUtils new DllUtils();
double[] desArray dllUtils.resampling(resamplingDTO.getSourceArray(), resamplingDTO.getGeneratingLength());
dllUtils.dispose();