使用Boost.Interprocess的Android C ++ IPC-应该可以吗? [英] Android C++ IPC using Boost.Interprocess - should it work?

查看:220
本文介绍了使用Boost.Interprocess的Android C ++ IPC-应该可以吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:

我在使用Boost IPC来访问共享内存的linux上有可用的C ++代码,我想将其移植到android.我下载并构建了在此处找到的Boost-for-Android项目: https://github.com/MysticTreeGames/Boost-for-Android .

I have working C++ code on linux that uses Boost IPC to access shared memory, and I want to port it to android. I downloaded and built the Boost-for-Android project found here: https://github.com/MysticTreeGames/Boost-for-Android.

问题:

但是,当我尝试创建一个这样的名为互斥体的增强功能时:

However when I try to create a boost named mutex like this:

boost::interprocess::named_mutex named_mtx(boost::interprocess::open_or_create, "my_mutex");

我得到一个异常,说没有这样的文件或目录",其本机代码为2.

I get an exception saying "no such file or directory" with a native code 2.

其他信息:

当我搜索如何在android上使用共享内存时,ashmem和Binder似乎是流行的方法,而我在移植的Boost IPC代码中根本找不到对它们的引用.

When I searched for how to use shared memory on android, it looks ashmem and Binder are popular methods, and I can't find references to them at all in the ported Boost IPC code.

问题:

  1. 没有这样的文件或目录"错误的原因是什么?
  2. 有人可以确认Boost-for-Android IPC部分有效吗?

推荐答案

默认情况下,Boost不会在Android上寻找共享数据的常用位置.它不是以这种方式构建的.要使其正常工作,请修改文件

By default Boost does not look for a common place where to share data on Android. It was not built this way. To make it work modify the file

    /boost/interprocess/detail/os_file_functions.hpp

在以下行中添加/sdcard

Find the following line an add /sdcard

    const char *names[]={ "/sdcard", ......

完成该操作后,使用该库并将其授予您的应用程序读/写外部存储权限.

After doing that use the library and give to your application Read/Write external storage permission.

你很好走.

PD:请小心.我在Android中使用Mutex和条件变量时遇到问题,因为该过程占用了100%的CPU.

PD: Please be carefull. I have problems using Mutex and conditional variables in Android because the process was taking 100% the CPU.

这篇关于使用Boost.Interprocess的Android C ++ IPC-应该可以吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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