VS2010+ICE3.5运行官方demo报错----std::bad_alloc

纠结了一晚上,在release版本下运行没问题,一到debug就报错,卡在

Ice::ObjectAdapterPtr adapter = ic->createObjectAdapterWithEndpoints("SimplePrinterAdapter","default -p 10000");

因为本人新手,只能求助google,百度。结果没能用的上的答案。

没办法,只有去官网求助了,终于找到一篇文档,看到标题就泪伤了,希望就这么悄无声息的。

Why does my application work fine in release mode but crash in debug mode?

http://doc.zeroc.com/pages/viewpage.action?pageId=2523181


原文:

The most common reason is a library mix-up. When you build your application in debug mode (that is, with _DEBUG defined), the compiler uses a debug version of the memory allocation and deallocation functions (see this MSDN page). When using Ice, memory is sometimes allocated by Ice and deallocated by the application (or vice-versa). You cannot allocate memory with the release version and deallocate this memory with the debug version, therefore it is critical that your application and the Ice libraries linked with your application use the same heap allocation functions.

The binary Ice distribution on Windows includes both debug and release libraries: use the import libraries with a d suffix (such as iced.lib and iceutild.lib) to link with the debug DLLs.


也就是说,debug模式下,运行的依赖库为

iced.lib
iceutild.lib

是有后缀的lib。


再啰嗦一句,在release模式下,引用的依赖库就是

ice.lib
iceutil.lib


当你看到"terminate called after throwing an instance of &#39;std::bad_alloc&#39;"的错误信息时,这意味着在程序运行过程中发生了内存分配失败的情况。 这个错误通常发生在使用new或new[]操作符时,当尝试分配一块内存时,由于内存不足或者无法分配足够的连续内存块,导致分配失败,从而触发了std::bad_alloc异常。 有几种可能的原因和解决方法: 1. 内存不足:如果系统内存不足,无法满足程序对内存的需求,就会导致分配失败。这时候可以尝试释放一些不再需要的内存资源,或者考虑优化程序的内存使用情况。 2. 内存泄漏:如果程序中存在内存泄漏,即分配了内存但未及时释放,导致内存资源耗尽,也会触发std::bad_alloc异常。在程序中仔细检查内存分配的位置,确保每次分配内存后都能正确释放。 3. 分配过大的内存块:如果尝试分配的内存块过大,超过了系统可用的内存大小,也会导致std::bad_alloc异常。可以尝试减小所需的内存大小,或者考虑使用其他的数据结构或算法来降低内存需求。 4. 操作符new的重载问题:如果程序中对new操作符进行了重载,可能存在重载函数中抛出std::bad_alloc异常的情况。检查程序中的new操作符重载函数,并确保它们正确处理了内存分配失败的情况。 总结来说,"terminate called after throwing an instance of &#39;std::bad_alloc&#39;"错误通常是由于内存分配失败引起的。要解决这个问题,需要检查程序中的内存使用情况、内存泄漏和内存需求等方面,以及对new操作符的重载情况。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [terminate called after throwing an instance of ‘stdbad_alloc‘问题原因与解决](https://blog.csdn.net/qq_44686646/article/details/127336434)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *3* [C++ new、delete(new[]、delete[])操作符重载需要注意的问题](https://download.csdn.net/download/weixin_38617615/13989552)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值