1
我有上面的方法序列化一個泛型類。在boost :: archive :: binary_iarchive上std :: bad_alloc
std::unique_ptr<Message> Serializer::deserialize(char* data , int size) {
std::stringstream ss(std::ios_base::in |
std::ios_base::out |
std::ios_base::binary);
ss.write(data, size);
Message *in;
boost::archive::binary_iarchive ia(ss, boost::archive::no_header);
ia >> in;
return std::unique_ptr<Message> (in);
}
我得到
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
,當我嘗試調用上一個char *,我肯定一體發送反序列化。 我嘗試反序列化的類,可以在這裏找到:
class DiscoveryMessage : public Message {
public:
DiscoveryMessage() {}
DiscoveryMessage(int tcpPort);
virtual ~DiscoveryMessage(){}
friend class boost::serialization::access;
private:
template <class Archive>
void serialize(Archive &ar, const unsigned int) {
// invoke serialization of base class (Message)
ar & boost::serialization::base_object<Message>(*this);
ar & mTcpReceivePort;
ar & mIPAddr;
}
int mTcpReceivePort;
std::string mIPAddr;
};