当我的代码只请求一个时,为什么 valgrind 报告两个内存分配?

Why is valgrind reporting two memory allocations when my code only requests one?

当我运行下面的程序通过valgrind(valgrind ./a.out --leak-check=yes):

int main() {
    char* ptr = new char;
    return 0;
}

该报告包含以下内容:

==103== error calling PR_SET_PTRACER, vgdb might block
==103==
==103== HEAP SUMMARY:
==103==     in use at exit: 1 bytes in 1 blocks
==103==   total heap usage: 2 allocs, 1 frees, 72,705 bytes allocated
==103==
==103== LEAK SUMMARY:
==103==    definitely lost: 1 bytes in 1 blocks
==103==    indirectly lost: 0 bytes in 0 blocks
==103==      possibly lost: 0 bytes in 0 blocks
==103==    still reachable: 0 bytes in 0 blocks
==103==         suppressed: 0 bytes in 0 blocks
==103== Rerun with --leak-check=full to see details of leaked memory

valgrind 报告的额外 72,704 字节分配是什么?它似乎在程序结束之前就已经处理好了,所以我猜这是编译器正在做的事情。我在 Windows 10.

的 Ubuntu 子系统上使用 gcc

编辑:在此示例中内存泄漏是故意的,但无论是否存在泄漏,我都会收到有关额外分配的类似消息。

如您所料,额外分配是运行时的一部分,并且如您在 Valgrind 的输出中所见,已正确清理。别担心。

如果您要具体询问它是什么,则必须阅读特定编译器和版本的 C++ 运行时库(libc,因为您使用的是 gcc)。但同样,这不应该与你有关。