升压进程间的Win32,64 [英] Boost interprocess Win32, x64
问题描述
我想用升压进程间不同的平台之间进行通信。
I want to communicate between different platforms using boost interprocess.
我使用VC12和Windows 7提高1.58。
I am using vc12 and boost 1.58 on windows 7.
我下面code是一个很简单的例子,应该工作。但它并不适用于不同势平台之间的通信...
My code below is a very simple example, that should work. But it doesn't for communications between diffrent platforms...
如果我在创建x64和在Win32中打开MSM,过程卡在锁在升压/ INT /同步/细节/ common_algorithms.hpp功能try_based_lock
If I create msm in x64 and open in win32, the process stuck at a lock at function try_based_lock in boost/int/sync/detail/common_algorithms.hpp
在周围的其他方法:WIN32创建,64开:在segment_manager_helper.hpp在name_length的进程崩溃whilr试图找到索引名称(priv_generic_find在segment_manager)
In the other way around: win32 create, x64 open: the process crashes at name_length in segment_manager_helper.hpp whilr trying to find the name in index (priv_generic_find in segment_manager).
在msm.find出现该问题(数据)
The problem occurs at msm.find("Data")
#include <iostream>
#include <boost/interprocess/managed_shared_memory.hpp>
int main() {
namespace bip = boost::interprocess;
// open in WIN32, create in x64
#ifndef _WIN64
bip::managed_shared_memory msm(bip::open_only, "TestIPC");
#else
bip::shared_memory_object::remove("TestIPC");
bip::managed_shared_memory msm(bip::create_only, "TestIPC", 4096);
msm.construct<uint32_t>("Data")[1](10);
#endif
// Get Data and print it
auto data = msm.find<uint32_t>("Data");
if (data.second == 1) {
std::cout << *data.first << std::endl;
}
std::cin.ignore();
return 0;
}
有谁有这样的经历?
Does anybody have experience in this?
推荐答案
的boost ::进程间
32位和64位模式之间的通信使用管理共享内存类似乎是不支持或错误。在那工作正常,虽然较低的水平。下面是示例code:
boost::interprocess
communication between 32 bit and 64 bit mode using managed shared memory classes seems to be either not supported or a bug. On the lower level that is working fine though. Here is the sample code:
#include <boost/interprocess/shared_memory_object.hpp>
#include <boost/interprocess/mapped_region.hpp>
#include <iostream>
int main(int argc, char *argv[])
{
using namespace boost::interprocess;
#ifndef _WIN64
shared_memory_object shm(open_only, "MySharedMemory", read_write);
mapped_region region(shm, read_only);
uint8_t *ptr = static_cast<uint8_t*>(region.get_address());
std::cout << int32_t(*ptr) << std::endl;
#else
shared_memory_object shm(create_only, "MySharedMemory", read_write);
shm.truncate(4096);
mapped_region region(shm, read_write);
uint8_t *ptr = static_cast<uint8_t*>(region.get_address());
*ptr = 5;
#endif
return 0;
}
这篇关于升压进程间的Win32,64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!