C++ 如何知道C++中的内存使用情况

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10183528/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 13:43:33  来源:igfitidea点击:

How to know the memory usage in C++

c++memorymemory-management

提问by LoveTW

I have a C++ program running by Visual Studio 2010, how can i monitor the the memory usage of my program? Does there exist simple API, such as i can call clock_t start1and start1 = clock();to monitor the time usage of my program. Thanks:)

我有一个由 Visual Studio 2010 运行的 C++ 程序,如何监控程序的内存使用情况?是否存在简单的API,例如我可以调用clock_t start1start1 = clock();监控我的程序的时间使用情况。谢谢:)

采纳答案by NattyBumppo

Memory management is not an easy problem like timing, and it is definitely more complicated to track.

内存管理不是像计时一样简单的问题,跟踪起来肯定更复杂。

I recommend looking at other similar StackOverflow posts to get started:

我建议您查看其他类似的 StackOverflow 帖子以开始使用:

How to analyse program's memory usage in Visual Studio 2010?

如何在 Visual Studio 2010 中分析程序的内存使用情况?

How do you detect/avoid Memory leaks in your (Unmanaged) code?

您如何检测/避免(非托管)代码中的内存泄漏?

track C++ memory allocations

跟踪 C++ 内存分配

These should help you solve whatever your specific memory-related problem is, whether it's looking for memory leaks, overwriting the end of an allocated buffer, or simply tracking how much memory you've allocated.

这些应该可以帮助您解决任何与内存相关的特定问题,无论是查找内存泄漏、覆盖已分配缓冲区的末尾,还是只是跟踪已分配的内存量。