【发布时间】:2015-05-22 09:34:55
【问题描述】:
valgrind 在一个用 gcc5.1 编译的空程序中检测到“仍然可达泄漏”,g++ ./a.cpp,
int main () {}
valgrind 说,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)
对于 c 程序,valgrinds 报告没有内存泄漏和内存分配。 此外,对于 gcc5.0 和 gcc4.9.2,valgrinds 也没有报告内存泄漏和内存分配。 那么,我猜是gcc5.1的新libstdc++造成的。
我的问题是如何减少可能在 libstdc++ 中的巨大内存分配。
确实,这个用-O3 编译的空c++ 程序的执行时间比一个空c 程序大几毫秒(没有systime)。
【问题讨论】:
-
您的文件只有
int main () {}吗?或者它有包含,等等? -
没有包含或链接用户指定的文件。
int main () {}就是内容,g++ ./a.cpp是我使用的编译命令。 -
所以真的只有
int main () {}...哇gcc...哇.... -
gcc -E a.cpp给你什么?.o长什么样子? -
g++ -E a.cpp说,#1“test.cpp”#1“”#1“”#1“” } 我认为objfile似乎很平常。没有不熟悉的符号。无论如何,user657267 建议的链接可能会说明问题。