gcc5.1的新libstdc++可能会分配大量堆内存
new libstdc++ of gcc5.1 may allocate large heap memory
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程序,valgrind不会报告内存泄漏和内存分配。此外,对于gcc5.0和gcc4.9.2, valgrind报告没有内存泄漏,也没有内存分配。那么,我猜gcc5.1的新libstdc++是原因。
我的问题是如何减少这种巨大的内存分配,这可能是在libstdc++。实际上,这个用-O3
编译的空c++程序的执行时间比一个空c程序的执行时间要长几毫秒(不含systime)。
空间被分配为libsup++中的紧急异常缓冲区
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64535开发人员说可能会在Valgrind中抑制追踪,但最终可能什么都没做。现在从跟踪中消除它的唯一方法可能是禁用异常,但这看起来都不是什么大问题,因为在程序退出之前,内存不能被回收用于其他事情。
相关文章:
- 在c++中为我自己的基于指针的数组分配内存的正确方法
- 给定一个指向堆分配内存的指针,智能指针实现如何为其找到合适的释放函数?
- 如果 const 不分配内存,为什么我可以获取 const 的地址?
- 在函数中分配内存时出现问题
- 如何为 std::vector 分配内存,然后稍后为某些元素调用构造函数?
- constexpr new 如何分配内存?
- 在构造函数中分配内存失败是如何冒泡的
- LLVM 传递以在特定地址分配内存
- CudaMalloc 在分配内存时失败
- 为什么它在不分配内存的情况下工作正常
- 为什么在正确解除分配内存时出现内存泄漏?
- 如何通过 malloc 为队列数组分配内存?
- vector是否为std::移动的对象连续分配内存
- 删除类成员的动态分配内存的最佳方法是什么
- 唯一指针是否在堆或堆栈上分配内存?
- 如果不分配内存,我如何能够为变量创建和分配值?
- std::initializer_list 堆是否分配内存?
- 如何按顺序或在指定的地址分配内存?
- 是否可以使用 malloc 为类对象分配内存?
- 迭代器是否分配内存(如指针)?