加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C的std :: string池,调试版本? std :: string和valgrind的问题

发布时间:2020-12-16 05:26:37 所属栏目:百科 来源:网络整理
导读:我有一个关于std :: string中可能的内存泄漏的许多valgrind警告的问题,像这样: 120 bytes in 4 blocks are possibly lost in loss record 4,192 of 4,687 at 0x4A06819: operator new(unsigned long) (vg_replace_malloc.c:230) by 0x383B89B8B0: std::stri
我有一个关于std :: string中可能的内存泄漏的许多valgrind警告的问题,像这样:
120 bytes in 4 blocks are possibly lost in loss record 4,192 of 4,687
    at 0x4A06819: operator new(unsigned long) (vg_replace_malloc.c:230)
    by 0x383B89B8B0: std::string::_Rep::_S_create(unsigned long,unsigned long,std::allocator<char> const&) (in /usr/lib64/libstdc++.so.6.0.8)
    by 0x383B89C3B4: (within /usr/lib64/libstdc++.so.6.0.8)
    by 0x383B89C4A9: std::basic_string<char,std::char_traits<char>,std::allocator<char> >::basic_string(char const*,std::allocator<char> const&) (in /usr/lib64/libstdc++.so.6.0.8)

我在想:

> std :: string(GCC 4.1.2)是否使用任何内存池?
>如果是,是否有任何方法来禁用池(以调试生成的形式等)?

解决方法

检查 FAQ.容器中有一个关于“内存泄漏”的部分.你应该

检查您的Valgrind版本>使用您的程序的调试版本(和未优化的)>并在必要时定义GLIBCXX_FORCE_NEW. (这是一个影响程序运行时行为的环境变量,而不是编译时#define,您可能会期望)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读