Bizzare memory problem..

Started by
3 comments, last by _the_phantom_ 20 years, 4 months ago
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&ltchar> 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);};
Advertisement
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]
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________
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

Globals are not evil. Singletons are evil.
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.
And the rockets' red glare, the bombs bursting in air,gave proof through the fight that our flag was still there.Oh say, does that star-spangled banner yet waveover the land of the free and the home of the brave?
yeah, i''ve just forced a completely clean recompile and its working now.
meh, should have thought of that myself, its been a long few days working on this however

Now, i just have to work out why my microthreads are blowing up :|

This topic is closed to new replies.

Advertisement