简体   繁体   English

调试高内存使用率

[英]Debug High Memory Usage

What are good tools/techniques for discovering which areas of the code are using a lot of memory? 有什么好的工具/技术可以发现代码的哪些区域正在使用大量内存? I've seen similar questions for linux that mention valgrind, but not one for a windows application developed with Visual Studio 2010. 我在linux上看到过类似的问题,其中提到了valgrind,但对于用Visual Studio 2010开发的Windows应用程序却没有一个问题。

There is also AQTime which can give you a list of allocated objects and a call-stack of where each object was created if you use the allocation profiler. 还有一个AQTime ,它可以为您提供已分配对象的列表,以及使用分配分析器时每个对象创建位置的调用堆栈。

Other options include manually instrumenting your code with instance counters for your objects to your code. 其他选项包括使用对象对象的实例计数器手动检测代码。 Not ideal but it can be useful especially if the profiling tool fails to run your application (eg due to low memory or instrumentation failures etc). 这不是很理想,但是很有用,特别是在性能分析工具无法运行您的应用程序时(例如,由于内存不足或检测故障等)。

What these tools often don't usually show in a very obvious way is memory fragmentation - which can easily occur if you have lots of large objects and lots of small objects being allocated and freed frequently in differing orders. 这些工具通常通常不会以非常明显的方式显示出内存碎片-如果您有很多大对象并且很多小对象经常以不同的顺序分配和释放,那么内存碎片很容易发生。 It can be worth using pools for some of these objects if possible and it can have drastic effects on memory usage and also performance in some situations. 如果可能的话,为其中一些对象使用池可能是值得的,并且在某些情况下可能对内存使用率和性能产生巨大影响。

The Microsoft CRT included with VS2010 has strong support for leak detection built in. Available in the crtdbg.h header, enabling it is described well in this MSDN library article . VS2010附带的Microsoft CRT对内置的泄漏检测功能提供了强大的支持。crtdbg.h标头中提供了此功能,在此MSDN库文章中对此进行了很好的描述。

If that's too much hardship then the Debugging Tools for Windows package can be very useful. 如果这太难了,那么Windows调试工具包可能会非常有用。 The UMHD (User Mode Heap Debugger) utility can report leakage without changing your program. UMHD(用户模式堆调试器)实用程序可以报​​告泄漏,而无需更改程序。

The Performance Wizard allows a very detailed view of resource utilization and can highlight single lines of code which lead to a high memory load. 通过性能向导,可以非常详细地查看资源利用率,并且可以突出显示一行代码,从而导致较高的内存负载。 To start the wizard, click on the Analyze menu of Visual Studio and then on Launch Performance Wizard. 要启动该向导,请单击Visual Studio的“分析”菜单,然后单击“启动性能向导”。 A premium version or higher may be required to run the full examination. 要进行全面检查,可能需要高级版本或更高版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM