在Android的NDK共享内存 [英] shared memory in android ndk

查看:1707
本文介绍了在Android的NDK共享内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从一个进程/应用程序在传输大量数据到另一个进程/应用程序的安卓,但一些如何创建共享内存使用内存文件中的的Java 层没有按'科技工作。

I wanted to transfer large data from one process/app to another process/app in Android, but some how creating shared memory using Memory File in Java layer doesn't work.

于是试图在Android原生创建共享内存,什么地方我看了
ashmem_create_region API可使用。不过貌似这个API是无法访问或打开。这里面libcutils.so。

So then tried to create shared Memory in android native, somewhere I read
ashmem_create_region API can be used. But looks like this API is not accessible or open. It is inside libcutils.so.

这是

android-ndk-r9c/platforms/android-19/arch-arm/usr/lib/rs/libcutils.so

Q1。如何访问该库在Android原生code。

Q1. How to access this library in android native code.

Q2。如果这是不可能访问又是什么在NDK工具给这个目的

Q2. If it is not possible to access then what is purpose of giving this in ndk tool.

Q3。如果不知何故,我挂libcutils.so,并能创建使用libcutils.so那我可以用这个的fd与MemoryFile用Java层映射,因此将避免应用本地副本写入每个数据事务在本机共享内存。

Q3. If somehow I linked libcutils.so and able to create shared Memory in native using libcutils.so Then can I use this fd to map with MemoryFile in Java layer so it will avoid application native copy to write for each data transaction.

推荐答案

libcutils.so 被运NDK启用的 renderscript整合。这仍然是一个未公开的系统库,在这个意义上,Android不承诺支持所有平台上的所有的API,特别是在未来的平台上,看到更多的在Android的NDK用户组

libcutils.so is shipped in ndk to enable renderscript integration. It remains an undocumented system library, in the sense that Android does not promise to support all its APIs on all platforms, and especially on future platforms, see more on on android-ndk user group.

这说,我应该承认,使用ashmem是相当安全的,因为它是明确的记载的Java API 的,因为第1节。我写了一个简短的解决方案在SO 链接其他地方对libcutils.so

This said, I should acknowledge that using ashmem is quite safe, as it is explicitly documented in Java API since v.1. I wrote a short solution for linking against libcutils.so elsewhere on SO.

下面是关于的注意事项与IPC通过这样的讨论ashmem_create_region() API和:的 https://groups.google.com/forum/m/#!topic/android-platform/L6a6Xvn4HSI TL; NR :你仍然需要粘结剂的握手

Here is a discussion about ashmem_create_region() API and caveats with IPC through this: https://groups.google.com/forum/m/#!topic/android-platform/L6a6Xvn4HSI. tl;nr: you still need Binder for handshake.

您的Java code可以访问 FD 使用一些的解决方法的。

Your Java code can access fd using some workarounds.

更新:新NDK的 r9d 是出来了,和 libcutils.so 不再是在平台/ Android的-19 /弓臂/ usr / lib目录目录, @Tim穆雷的承诺在下面的评论。

Update: new NDK r9d is out, and libcutils.so is no longer in the platforms/android-19/arch-arm/usr/lib directory, as @Tim Murray promised in comments below.

这篇关于在Android的NDK共享内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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