Archived

This topic is now archived and is closed to further replies.

Bizzare memory problem..

This topic is 5115 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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);};

Share this post


Link to post
Share on other sites
Have you recently added any members to your class? If so, make sure that you recompile all dependant code. If some code dealing with your class thinks it is a different size than it actually is, then the wrong variable can easily be written to. This is the first thing that comes to mind with the problem you described.

______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________


[edited by - Thunder_Hawk on December 13, 2003 11:27:26 PM]

Share this post


Link to post
Share on other sites
For my experience with VS.NET, I would actually recommend simply recompiling everything, as in deleting the whole "Debug" or "Release" folder and start from scratch.

VS.NET tries to be lazy by doing an incremental compile and making only the needed changes to object files, then re-linking them together into the executable. But I''ve noticed that it doesn''t always work. I''m not sure of the exact fail conditions, but I''ve always made it a point to do full rebuilds when working with Microsoft compilers. It''s just safer.



"Remember: Silly is a state of Mind, Stupid is a way of Life." -- Dave Butler

Share this post


Link to post
Share on other sites
quote:
Original post by Indigo Darkwolf
For my experience with VS.NET, I would actually recommend simply recompiling everything, as in deleting the whole "Debug" or "Release" folder and start from scratch.

VS.NET tries to be lazy by doing an incremental compile and making only the needed changes to object files, then re-linking them together into the executable. But I''ve noticed that it doesn''t always work. I''m not sure of the exact fail conditions, but I''ve always made it a point to do full rebuilds when working with Microsoft compilers. It''s just safer.



"Remember: Silly is a state of Mind, Stupid is a way of Life." -- Dave Butler



Same with me. I always rebuild my project instead of compiling it.

Share this post


Link to post
Share on other sites