C++ 中的内存分配分析

2021-12-24 00:00:00 profiling memory-management c++

我正在编写一个应用程序,并惊讶地发现它的总内存使用量已经太高了.我想分析我的应用程序的动态内存使用情况:堆中每种类型的对象有多少,哪些函数创建了这些对象?另外,每个对象使用了多少内存?

I am writing an application and am surprised to see its total memory usage is already too high. I want to profile the dynamic memory usage of my application: How many objects of each kind are there in the heap, and which functions created these objects? Also, how much memory is used by each of the object?

有没有简单的方法可以做到这一点?我在 linux 和 windows 上工作,所以任何平台的工具就足够了.

Is there a simple way to do this? I am working on both linux and windows, so tools of any of the platforms would suffice.

注意:我不关心这里的内存泄漏.

NOTE: I am not concerned with memory leaks here.

推荐答案

您是否尝试过 Valgrind?它是 Linux 的分析工具.它有一个名为 Memcheck 的内存检查器(用于内存泄漏和其他内存问题),但它还有一个名为 Massif 的堆分析器.

Have you tried Valgrind? It is a profiling tool for Linux. It has a memory checker (for memory leaks and other memory problems) called Memcheck but it has also a heap profiler named Massif.

相关文章