Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/131.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 微软C++;异常:boost::archive::archive_内存位置异常(通过客户端服务器boost Udp解析向量)_C++_Memory_Serialization_Boost_Deserialization - Fatal编程技术网

C++ 微软C++;异常:boost::archive::archive_内存位置异常(通过客户端服务器boost Udp解析向量)

C++ 微软C++;异常:boost::archive::archive_内存位置异常(通过客户端服务器boost Udp解析向量),c++,memory,serialization,boost,deserialization,C++,Memory,Serialization,Boost,Deserialization,我发现这并没有用,因为他在做文件,而我只想做向量 问题:我在服务器端对向量进行了序列化,并解析到客户端,然后在那里进行反序列化。因此,对于1/2的记录来说,一切都很顺利 但如果我插入了2条以上的记录并通过向量解析它,它在客户端反序列化数据时给了我这个错误:微软C++异常:Booo:::归档:在内存位置异常/p> 这是我的代码: 服务器端: 通过将向量作为输入来序列化数据 //I think these headers are enough !!! #include <boost/arch

我发现这并没有用,因为他在做文件,而我只想做向量

问题:我在服务器端对向量进行了序列化,并解析到客户端,然后在那里进行反序列化。因此,对于1/2的记录来说,一切都很顺利

但如果我插入了2条以上的记录并通过向量解析它,它在客户端反序列化数据时给了我这个错误:微软C++异常:Booo:::归档:在内存位置异常/p> 这是我的代码:

服务器端:

通过将向量作为输入来序列化数据

//I think these headers are enough !!!

#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include<boost/serialization/vector.hpp>
#include<boost/serialization/map.hpp>

template<class input>
void UdpServer::serializeData(input &vector) { // Here i use vector in parameter
    std::ostringstream archive_stream;
    boost::archive::text_oarchive archive(archive_stream);
    archive << vector;
    sendMessageToClients(archive_stream.str());//sending to client
}
任何帮助都将不胜感激

提前感谢,

archive << vector;
建议您反序列化
std::map

那不行。事实上,这很可能会发生

我想你必须把尺码报出来

 boost::asio::buffer(recv_buf,1024), m_sender_endpoint);

在这一行中,也适用于服务器端。

这缺少一个。这里有太多未知类型和变量。你的问题是要包含足够的代码,我们才能编译它。是不是序列化数据超过了数据包大小?我想这是@sehe的可能性,但有没有办法设置它的大小?@1201程序哪些变量你不懂?在
序列化数据中使用的类
输入
archive\u data
中使用的
map
的类和类型。
archive << vector;
archive >> map;
//this is what i received from the server
size_t const len = m_socket.receive_from(
    boost::asio::buffer(recv_buf,1024), m_sender_endpoint);
 boost::asio::buffer(recv_buf,1024), m_sender_endpoint);