问题描述
||
我使用boost :: interprocess :: managed_(windows_)shared_memory :: construct构造一个拥有自己类的进程间向量,该类具有一个成员变量std :: string和另一个类型std :: vector,所以:
class myclass
{
public:
myclass()
{
}
std::string _mystring;
std::vector < int > _myintvector;
};
template < class _type >
struct typedefs
{
typedef boost::interprocess::managed_windows_shared_memory _memory;
typedef _memory::segment_manager _manager;
typedef boost::interprocess::allocator < _type,_manager > _allocator;
typedef boost::interprocess::vector < _type,_allocator > _vector;
};
typedef typedefs < myclass > tdmyclass;
int main ()
{
using namespace boost::interprocess;
managed_windows_shared_memory mem ( open_or_create,\"mysharedmemory\",65536 );
tdmyclass::_vector * vec = mem.construct < tdmyclass::_vector > ( \"mysharedvector\" ) ( mem.get_segment_manager() );
myclass mytemp;
mytemp._mystring = \"something\";
mytemp._myintvector.push_back ( 100 );
mytemp._myintvector.push_back ( 200 );
vec->push_back ( mytemp );
/* waiting for the memory to be read is not what this is about,so just imagine the programm stops here until everything we want to do is done */
}
我只是为了测试而做,我预计std :: string和std :: vector都不起作用,但是,如果我从另一个进程中读取它,则std :: string实际上有效,它包含我分配的字符串。真的让我感到惊讶。
另一侧的std :: vector仅部分起作用,size()返回的值是正确的,但是如果我要访问迭代器或使用operator [],则程序崩溃。
所以,我的问题是,为什么会这样呢?我的意思是,我从未真正阅读过Visual Studio SDK的STL实现,但std :: string仅仅是具有附加功能的std :: vector的新功能吗?他们不是都使用std :: allocator-这意味着std :: string和std :: vector都不能在共享内存中工作吗?
谷歌搜索实际上并没有导致什么,除了boost :: interprocess :: vector,那不是我搜索的内容。所以我希望有人能给我一些有关发生的事情的详细信息^^
PS:如果我在上面的代码中打错了文字,请原谅我,我现在才在此页面编辑器中编写它,我还用一种方式来自动完成我的IDE ^^
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)