vc2005 stringstream 内存泄漏

Visual Studio and .NET Framework
反馈解决方法
98861. 2005 CRT memory leaks: std::basic_iostream ( affects std::stringstream, std::fstream, probably others )
std::iostream leaks memory in trivial code. This is compounded to any class that inherits from std::iostream (such as std::stringstream) also leaks.
已关闭 填写的反馈 2005/11/9 填写者 mike_n
填写者 mike_n 日期 2005/12/5
This workaround involves modifying constructors for basic_istream and basic_ostream in the source distribution of the MS Visual C++ libraries and rebuilding msvcp80.dll and msvcr80.dll. NOTE: Only the DLL builds of these libraries were tested and only the instructions for using these libraries is provided here. The code mentioned in the bug description and my own application were tested to verify the fix.

References:

P.J. Plauger, Dinkumware - Supplied the modified constructors.

"Building the Run-Time Libraries, MSDN2 online, http://msdn2.microsoft.com/en-us/library/k9a8ehy3.aspx - How to rebuild the MSVC runtime libraries.

1. Change the relevant constructor in

{C:/Program Files/Microsoft Visual Studio 8}/vc/include/istream and
{C:/Program Files/Microsoft Visual Studio 8}/vc/crt/src/istream
* directory between {} is the location of the MSVC 8 install directory

explicit __CLR_OR_THIS_CALL basic_iostream(basic_streambuf<_Elem,_Traits> *_Strbuf)
        : basic_istream<_Elem, _Traits>(_Strbuf, false),
            basic_ostream<_Elem, _Traits>(_Noinit, false)
        {    // construct from stream buffer pointer
        }

2. Change the relevant constructor in

{C:/Program Files/Microsoft Visual Studio 8}/vc/include/ostream and
{C:/Program Files/Microsoft Visual Studio 8}/vc/crt/src/ostream

__CLR_OR_THIS_CALL basic_ostream(_Uninitialized, bool _Addit = true)
        {    // construct uninitialized
        if (_Addit)
            ios_base::_Addstd(this);    // suppress for
iostream
        }

3. Rebuild the MSVC libraries by running:

{C:/Program Files/Microsoft Visual Studio 8}/vc/crt/src/bldnt.cmd
* See reference link from description for details on rebuilding the MSVC libraries.

4. Modify the Visual Studio project files

a. Properties->Linker->Input , "Ignore Specific Libraries" : msvcprt.lib;msvcrt.lib
b. Properties->Linker->Input, "Additional Dependencies" :
"{C:/Program Files/Microsoft Visual Studio 8}/vc/crt/src/build/intel/sample_p.lib"
"{C:/Program Files/Microsoft Visual Studio 8}/vc/crt/src/build/intel/_sample_.lib"
* Refer to reference link from description on details of the file naming.

5. Put the sample_p.dll and _sample_.dll in the same directory as your app ( or follow the rules for side-by-side deployment).


填写者 Mark Bartosik 日期 2006/10/27
Maybe I'm too tired but the work around from
mike_n on 12/5/2005
does not appear to compile

填写者 MikWells 日期 2007/1/15
This memory leak has been fixed in Service Pack 1, which was release to the public in December 2006. As well as installing the entire Service Pack (over 400MB) on your development machine, you will also have to install the updated VC8 distributable runtime libraries on any machine that your program run ons.

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值