简体   繁体   English

如何在android本机代码中使用共享内存?

[英]How to use shared memory in android native code?

I am porting an existing linux application to android.我正在将现有的 linux 应用程序移植到 android。 The application is using shared memory API's like shm_open() etc.该应用程序正在使用共享内存 API,如shm_open()等。

Checking bionic in android source , I see that these API's are not supported.检查android source 中的仿生,我发现这些 API 不受支持。 Hence I get a linking error during build.因此我在构建过程中遇到链接错误。

external/l2/avbtp.c:138: error: undefined reference to 'shm_open'
external/l2/avbtp.c:151: error: undefined reference to 'shm_unlink'
external/l2/avbtp.c:186: error: undefined reference to 'shm_unlink'

How to resolve this correctly?如何正确解决这个问题?

Android intentionally doesn't provide SysV IPC . Android 故意不提供 SysV IPC Try to avoid using of shared memory or, if you really want, look for examples of using ashmem .尽量避免使用共享内存,或者,如果你真的想要,寻找使用ashmem例子。

Well, I found this github project and well it works! 好吧,我找到了这个github项目,并且很好用! https://github.com/pelya/android-shmem https://github.com/pelya/android-shmem

Like a magic, it works perfectly. 就像魔术一样,它运作完美。 You can use shared memory in android across independent processes using shmget(), shmat() and shmdt() API's seamlessly. 您可以无缝地使用shmget(),shmat()和shmdt()API在独立进程中使用android中的共享内存。 Give it a try. 试试看。

yeh I have seen that project but I'm confused how to use it. 是的,我看过那个项目,但是我很困惑如何使用它。 I just want to deploy postgresql on my android phone properly but I'd doesnt work with ashmmem so I need to use this emulator the problem is I'm just a beginner and those explanation wasn't comprehensible enough . 我只想在我的安卓手机上正确部署postgresql,但是我不能和ashmmem一起工作,所以我需要使用这个模拟器,问题是我只是一个初学者而这些解释还不够清楚。 😢 😢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM