[英]Enumerate allocated objects
How do I enumerate all allocated objects (allocated by the new operator) (not only those which have their own memory mappings, but those which are on the heap, too?) in C++? 如何在C ++中枚举所有分配的对象(由new运算符分配)(不仅具有自己的内存映射的那些对象,而且还具有堆上的那些对象?)?
I need this to find memory leaks. 我需要这个来查找内存泄漏。
Platform: Linux, gcc, i386,AMD_K64 (better: Platform independent) 平台:Linux,gcc,i386,AMD_K64(更好:与平台无关)
There may be no official way, but there may be a lean workaround. 可能没有官方的方法,但是可能有一个精益的解决方法。 For example, is there some internal variable you could access?
例如,您可以访问一些内部变量吗? Maybe a pointer to the list used for management of the heap?
也许是指向用于堆管理的列表的指针?
You always can use valgrind to check for memory leaks. 您始终可以使用valgrind检查内存泄漏。 Either install it with your package manager or just download and compile from: http://valgrind.org/
可以使用软件包管理器进行安装,也可以直接从以下网址下载并进行编译: http : //valgrind.org/
If you compile your application in debug mode it can pinpoint down to the file/line where you have allocated resources that were not freed/deleted. 如果您在调试模式下编译应用程序,则可以精确定位到分配了未释放/删除的资源的文件/行。
您可以使用valgrind来实现您想要的功能(将malloc替换为其自己的实现)并计算分配/释放
There are potentially two forms of memory lose 可能有两种形式的内存丢失
I'm sure there are more tools out there. 我确定那里还有更多工具。 These are pretty popular.
这些很受欢迎。
In Solaris, I'd recommend libumem for leak tracking and analyzer in Sun's Studio for profiling and memory analysis. 在Solaris中,我建议libumem用于Sun Studio中的泄漏跟踪和分析器,以进行性能分析和内存分析。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.