I''m not quite sure why this is happening, infact i''ve never seen this happen before with stuff i''ve done, but for some reason while trying to push_back() a class onto an std::list its mucking up a vector<char> i''ve got stored in the class.
Relivent bits of code are :
class connectiondetails
{
public:
SOCKET socket; // socket to send on
sockaddr_in addr; // address to send to
std::vector<char> data; // data to send
MicroThreadSystem::MicroThread * sender; // class doing the sending
connectiondetails(){};
connectiondetails(const connectiondetails & cd)
{
addr = cd.addr;
socket = cd.socket;
data.reserve(cd.data.size());
data.assign(cd.data.begin(),cd.data.end());
sender = cd.sender;
}
};
void ConnectionSender::AddtoSend(connectiondetails &details)
{
m_sendqueue.push_back(details);
}
Now, i''ve traced it in debug mode, and stepping through the copy-constructor, it seems to setup the data vector correctly, however I tend traced into the STL itself and the point it seems to go wrong is indicated here :
_Nodeptr _Buynode(_Nodeptr _Next,
_Nodeptr _Prev, const _Ty& _Val)
{ // allocate a node and set links and value
_Nodeptr _Pnode = this->_Alnod.allocate(1);
_TRY_BEGIN
new ((void *)_Pnode) _Node(_Next, _Prev, _Val); // after here the data is wrong, just shows ''bad_ptr'' in the debug window
_CATCH_ALL
this->_Alnod.deallocate(_Pnode, 1);
_RERAISE;
_CATCH_END
return (_Pnode);
}
If anyone has any ideas why this could be happening, and how i might be able to fix it i''d appricate it
For the record i''m using VS.Net03 on WinXP
I''ve been pushing stuff back onto lists in other parts of this program with no trouble.
Below is the code which gets me to the point above
void SendInitalData()
{
std::vector<char> query; // query to send
std::string request("\\status");
query.reserve(request.length()+1);
// strcpy(query[0],request.c_str()); // copy into the query buffer
query.assign(request.size(),*(request.c_str()));
strcpy(&query[0],request.c_str());
// if(!m_connection.expired())
{
boost::shared_ptr<Networking::ConnectionObject> connection = m_connection.lock();
connection->Write(m_addr,query);
final = false;
}
}
// allows data to be sent out via its socket
void ConnectionObject::Write(sockaddr_in &addr,std::vector<char> &data)
{
connectiondetails details;
details.addr = addr;
details.data.reserve(data.size());
details.data.assign(data.begin(),data.end());
//details.data = *data;
details.socket = socket;
// g_ConnectionMapper.AddToSend(details);
Networking::ConnectionMapper::GetSingleton().AddToSend(details);
// sendto(socket,static_cast<char *>(&data[0]),data.size(),&Addr, sizeof(Addr));
}
void ConnectionMapper::AddToSend(connectiondetails &details){sender->AddtoSend(details);};