C ++的std :: string池,调试构建? std :: string和valgrind的问题 [英] C++'s std::string pools, debug builds? std::string and valgrind problems
本文介绍了C ++的std :: string池,调试构建? std :: string和valgrind的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个问题,许多valgrind警告可能的内存泄漏std :: string,像这样:
120 4个块中的字节可能在丢失记录中丢失4,192
/ pre>
$ 0x4A06819:operator new(unsigned long)(vg_replace_malloc.c:230)
由0x383B89B8B0:std :: string :: _ Rep :: _ S_create (unsigned long,unsigned long,std :: allocator< char> const&)(在/usr/lib64/libstdc++.so.6.0.8中)
by 0x383B89C3B4:(在/usr/lib64/libstdc++.so。 6.0.8)
by 0x383B89C4A9:std :: basic_string< char,std :: char_traits< char>,std :: allocator< char> > :: basic_string(char const *,unsigned long,std :: allocator< char> const&)(在/usr/lib64/libstdc++.so.6.0.8中)
我想知道:
- does std :: string
- 如果是这样,是否有任何方式禁用池(以调试版本等形式)?
解决方案
检查常见问题。有一个关于容器中的内存泄漏的部分。您应该
- 检查您的Valgrind版本
- 使用您的程序的调试版本 - 优化)
- 并在必要时定义
GLIBCXX_FORCE_NEW
。 (这是影响程序运行时行为的环境变量,而不是您可能期望的编译时#define
。)
I have a problem with many valgrind warnings about possible memory leaks in std::string, like this one:
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*, unsigned long, std::allocator<char> const&) (in /usr/lib64/libstdc++.so.6.0.8)
I'm wondering:
- does std::string (GCC 4.1.2) use any memory pools?
- if so, is there any way to disable the pools (in form of a debug build etc.)?
解决方案
Check the FAQ. There is a section about "Memory leaks" in containers. You should
- check your version of Valgrind
- use a debug build of your program (and un-optimized)
- and define
GLIBCXX_FORCE_NEW
if necessary. (This is an environment variable that affects your program's runtime behavior, not a compile-time#define
as you might expect.)
这篇关于C ++的std :: string池,调试构建? std :: string和valgrind的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文