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

本文深入探讨了C++中std::deque容器在内存管理方面的特性,通过实例展示了如何正确使用deque避免内存泄漏,并在Debug与Release模式下进行对比分析。
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,访问操作非法。难道在

Process name is com.oplus.camera, uid is 10158, not key_process keyProcess: 0 *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** Build fingerprint: realme/RMP2502IN/RE6453L1:16/BP2A.250605.015/B.R4T1.47a0950-26d089e-26d0a14:user/release-keys Revision: 0 ABI: arm64 Timestamp: 2025-11-11 23:44:48.477685001+0800 Process uptime: 450s Cmdline: com.oplus.camera pid: 5867, tid: 5870, name: Jit thread pool >>> com.oplus.camera <<< uid: 10158 tagged_addr_ctrl: 0000000000000001 (PR_TAGGED_ADDR_ENABLE) signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x00d28606563d752f x0 0000007447291d58 x1 0000007250c01010 x2 000000000000000d x3 0000000000000010 x4 0000000000000000 x5 00000000000001f1 x6 0000000000ffff5a x7 0000000000ff09b0 x8 0000007241a01010 x9 0000007250c01010 x10 d5d28606563d752f x11 00000071bf401010 x12 0000000000000007 x13 0000000000000009 x14 0000000000000009 x15 0000000000000001 x16 0000000000000001 x17 00000074d02e0750 x18 00000073adc3c000 x19 0000007250c00000 x20 000000744728fb40 x21 0000000000000010 x22 000000000000000d x23 00000000000001f1 x24 0000000000000000 x25 00000074d035e000 x26 0000007250c00078 x27 00000000000001f1 x28 00000000003e3ff0 x29 000000740b06c820 lr 00000074d02aa940 sp 000000740b06c820 pc 00000074d02aac54 pst 0000000060001000 19 total frames backtrace: #00 pc 0000000000068c54 /apex/com.android.runtime/lib64/bionic/libc.so (arena_run_heap_remove+52) (BuildId: 65b0c8857610bf85fb81a624be775cc4) #01 pc 000000000006893c /apex/com.android.runtime/lib64/bionic/libc.so (arena_run_split_remove+76) (BuildId: 65b0c8857610bf85fb81a624be775cc4) #02 pc 00000000000686a0 /apex/com.android.runtime/lib64/bionic/libc.so (arena_run_split_large_helper+224) (BuildId: 65b0c8857610bf85fb81a624be775cc4) #03 pc 0000000000062648 /apex/com.android.runtime/lib64/bionic/libc.so (arena_purge_to_limit+360) (BuildId: 65b0c8857610bf85fb81a624be775cc4) #04 pc 0000000000062304 /apex/com.android.runtime/lib64/bionic/libc.so (je_arena_maybe_purge+836) (BuildId: 65b0c8857610bf85fb81a624be775cc4) #05 pc 0000000000064ad4 /apex/com.android.runtime/lib64/bionic/libc.so (arena_dalloc_bin_locked_impl+516) (BuildId: 65b0c8857610bf85fb81a624be775cc4) #06 pc 0000000000064be4 /apex/com.android.runtime/lib64/bionic/libc.so (je_arena_dalloc_small+132) (BuildId: 65b0c8857610bf85fb81a624be775cc4) #07 pc 0000000000076a44 /apex/com.android.runtime/lib64/bionic/libc.so (je_free+132) (BuildId: 65b0c8857610bf85fb81a624be775cc4) #08 pc 0000000000366538 /apex/com.android.art/lib64/libart.so (std::__1::deque<elf64_sym, std::__1::allocator<elf64_sym>>::~deque[abi:nn200000]()+124) (BuildId: 80d2ab18f9d259d8e546c1e6bae752b1) #09 pc 000000000036604c /apex/com.android.art/lib64/libart.so (art::ElfBuilder<art::ElfTypes64>::~ElfBuilder()+256) (BuildId: 80d2ab18f9d259d8e546c1e6bae752b1) #10 pc 0000000000366f6c /apex/com.android.art/lib64/libart.so (art::debug::MakeElfFileForJIT(art::InstructionSet, art::InstructionSetFeatures const*, bool, art::debug::MethodDebugInfo const&)+292) (BuildId: 80d2ab18f9d259d8e546c1e6bae752b1) #11 pc 00000000004bc4cc /apex/com.android.art/lib64/libart.so (art::OptimizingCompiler::JitCompile(art::Thread*, art::jit::JitCodeCache*, art::jit::JitMemoryRegion*, art::ArtMethod*, art::CompilationKind, art::jit::JitLogger*)+1144) (BuildId: 80d2ab18f9d259d8e546c1e6bae752b1) #12 pc 000000000060d490 /apex/com.android.art/lib64/libart.so (art::jit::JitCompiler::CompileMethod(art::Thread*, art::jit::JitMemoryRegion*, art::ArtMethod*, art::CompilationKind)+1388) (BuildId: 80d2ab18f9d259d8e546c1e6bae752b1) #13 pc 0000000000493780 /apex/com.android.art/lib64/libart.so (art::jit::Jit::CompileMethodInternal(art::ArtMethod*, art::Thread*, art::CompilationKind, bool)+368) (BuildId: 80d2ab18f9d259d8e546c1e6bae752b1)
最新发布
11-13
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值