【发布时间】:2018-06-24 04:30:18
【问题描述】:
我有一个结构实例,它通过 Boost 进程间传递给 TCP/IP 客户端,在客户端中,我需要使用 Boost 序列化库对其进行序列化。由于这个结构包含 boost::interprocess basic_string,它不能直接序列化,所以我正在通过使用它们在序列化函数中构造 std::string 来解决这个问题。
using CharAllocator = boost::interprocess::allocator<char, boost::interprocess::managed_shared_memory::segment_manager>;
using MyShmString = boost::interprocess::basic_string<char, std::char_traits<char>, CharAllocator>;
MyShmString uuid_;
template<typename _Archive>
void save( _Archive &ar, unsigned int const version ) const
{
ar << std::string{ this->uuid_.c_str(), this->uuid_.length() };
}
template<typename _Archive>
void load( _Archive &ar, unsigned int const version )
{
auto tmp = std::string{};
ar >> tmp; this->uuid_ = tmp.c_str();
}
如果没有构造函数开销,有没有更好的方法来执行此操作?
【问题讨论】:
-
pse展示它是如何将它的“传递给TCP / IP客户端 i>”。 span>
-
@RustyX 我会,但代码太多了,它只是一个进程间双端队列
标签: c++ boost boost-serialization boost-interprocess