共享Java服务,并以最少的开销访问本机应用程序之间的缓冲 [英] sharing a buffer between a Java service and a native app with minimal access overhead

查看:213
本文介绍了共享Java服务,并以最少的开销访问本机应用程序之间的缓冲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个Android的Java服务和本机进程之间共享内存区域。本机进程没有Java组件,纯粹是C ++,并且从外壳直接用命令行调用。

I am trying to set up a shared memory region between an Android Java service and a native process. The native process has no Java component, is purely C++, and is invoked from the shell directly by a command line.

我相信,我可以使用ashmem和粘结剂做到这一点。第一呼叫ashmem_create_region,该结果呼叫MMAP,然后将所得的fd使用粘合剂传递到其他处理。其他过程中的mmap的FD,并由此获得访问共享区域

I believe that I can use ashmem and binder to accomplish this. First call ashmem_create_region, call mmap on the result, then pass the resulting fd to the other process using binder. The other process does mmap on the fd and thereby gains access to the shared region.

据我所知,这个工程两个Java应用程序之间,也是一个Java应用程序或服务,本机模式进程之间的工作。

I understand that this works between two Java apps and also works between a Java app or service and a native mode process.

我现在想知道如何在Java服务可以有效地访问数据。我想用这个机制来复制花车的缓冲区,大小约为300MB,从本机应用程序的Java服务。现在,Java服务,而不需要开销如用JNI发生访问这些数据。什么是分配的共享区域,使得本机程序可以做花车快速复制到缓冲区和Java服务可以以最小的开销访问值的最佳策略是什么?

I am wondering now how the Java service can access the data efficiently. I want to use this mechanism to copy a buffer of floats, about 300MB in size, from the native app to the Java service. Now the Java service needs to access this data without overheads such as occurs with JNI. What is the best strategy for allocating the shared region so that the native program can do fast copy of the floats into the buffer and the Java service can access the values with minimal overhead?

感谢

推荐答案

对此例子看看。
它创建Java和本机应用程序之间共享内存。
https://github.com/vecio/AndroidIPC

这篇关于共享Java服务,并以最少的开销访问本机应用程序之间的缓冲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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