从 C++ 应用程序查询堆

Querying the heap from a C++ application

我想解决使用 C++ 运行-Time 库的 C++ 本机应用程序中的内存泄漏问题。我可以很容易地知道当前分配的块数(以及可选的总大小)吗?

您可以尝试 Massif 来自 Valgrind。

Massif is a heap profiler. It measures how much heap memory your program uses. [...] Also, there are certain space leaks that aren't detected by traditional leak-checkers,

您可以尝试 HeapWalk in the Heap API,不需要第 3 方库。

在 windows 上,您可以在 linux valgrind 上使用 Dr Memory。也可以在 linux 上使用带有 gcc 的泄漏消毒剂或带有 -fsanitize=leak 的 clang,但您还需要一些运行时支持(您需要 link 到其他一些库以获得 gcc 或 clang 消毒剂)。