std::deque 在Debug 与Release 下执行的不同

本文深入探讨了C++中std::deque容器在内存管理方面的特性,通过实例展示了如何正确使用deque避免内存泄漏,并在Debug与Release模式下进行对比分析。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

typedef struct _device_callstation_info
{
	int nGuid;
	/*设备名字*/
	char szName[JH_DEVICE_NAME_LEN+1];
	std::deque<STRUCT_DEVICE_CALLSTATION_ZONE> * pDequeZone;

	_jinhong_device_callstation_info()
	{
		nGuid = 0;
		memset( szName, 0, sizeof(szName) );
		pDequeZone = new std::deque<STRUCT_DEVICE_CALLSTATION_ZONE>;
	}
	_device_callstation_info & operator = ( _device_callstation_info & s  )
	{
		nGuid = s.nGuid;
		memset( szName, 0, sizeof(szName) );
		strcpy( szName, s.szName );
		pDequeZone->clear();
		std::deque<STRUCT_DEVICE_CALLSTATION_ZONE>::iterator itZone;
		for ( itZone = s.pDequeZone->begin(); itZone != s.pDequeZone->end(); itZone++ )
		{
			pDequeZone->push_back( *itZone );/*在此处Debug, Release 下不一样*/
		}
		return *this;
	}
	~_device_callstation_info()
	{
		nGuid = 0;
		memset( szName, 0, sizeof(szName) );
		if ( pDequeZone && !pDequeZone->empty() )
		{
			pDequeZone->clear();
			delete pDequeZone;
		}
	}

}STRUCT_DEVICE_CALLSTATION;


然后声明CArray<STRUCT_DEVICE_CALLSTATION,STRUCT_DEVICE_CALLSTATION&> arrCallstation;

STRUCT_DEVICE_CALLSTATION newCallstation;

. 设置值

arrCallstation.Add( newCallstation);


然后重开一个线程取值,也就是在newCallstation销毁后取值。

STRUCT_DEVICE_CALLSTATION newCallstation;

newCallstation = arrCallstation[0];

就在代码标识的地方(Release版本下)出现错误。


如上,声明为指针方式 ,在Debug与Release 下均正常。

std::deque<STRUCT_DEVICE_CALLSTATION_ZONE> * pDequeZone;

如果声明为一般变量,则在Debug下正常,而在Release下不正常。

std::deque<STRUCT_DEVICE_CALLSTATION_ZONE> dequeZone;

在代码的中的不正常的位置已经标识。*itZone,访问操作非法。难道在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值