Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

new libstdc++ of gcc5.1 may allocate large heap memory

Tags:

c++

c

gcc

valgrind

valgrind detects "still reachable leak" in an empty program compiled with gcc5.1, g++ ./a.cpp,

int main () {}

valgrind says, valgrind ./a.out,

==32037== HEAP SUMMARY:
==32037==     in use at exit: 72,704 bytes in 1 blocks
==32037==   total heap usage: 1 allocs, 0 frees, 72,704 bytes allocated
==32037== 
==32037== LEAK SUMMARY:
==32037==    definitely lost: 0 bytes in 0 blocks
==32037==    indirectly lost: 0 bytes in 0 blocks
==32037==      possibly lost: 0 bytes in 0 blocks
==32037==    still reachable: 72,704 bytes in 1 blocks
==32037==         suppressed: 0 bytes in 0 blocks
==32037== Rerun with --leak-check=full to see details of leaked memory
==32037== 
==32037== For counts of detected and suppressed errors, rerun with: -v
==32037== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 5 from 5)

For c programs, valgrinds reports no memory leaks and no memory allocation. In addition, for gcc5.0 and gcc4.9.2, valgrinds reports no memory leaks and no memory allocation too. Then, I guess that new libstdc++ of gcc5.1 is the cause.

My question is how to reduce this huge memory allocation which may be in libstdc++. Indeed, the execution time of this empty c++ program compiled with -O3 is larger than one of the empty c program by a few milliseconds (without systime).

like image 546
akakatak Avatar asked May 22 '15 09:05

akakatak


1 Answers

The space is allocated as an emergency exception buffer in libsup++

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64535

the devs talk of maybe suppressing the trace in Valgrind but presumably nothing was done in the end. The only way of eliminating it from the trace right now would probably be to disable exceptions, but it doesn't look like it's a big deal either way, it's not as if the memory can be reclaimed for something else before the program exits.

like image 152
user657267 Avatar answered Oct 19 '22 00:10

user657267