GCC内存泄漏检测相当于微软crtdbg.h? [英] GCC memory leak detection equivalent to Microsoft crtdbg.h?

查看:861
本文介绍了GCC内存泄漏检测相当于微软crtdbg.h?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过多年的通用C ++使用Visual Studio中的微软MSVC编译器库,我们现在将它移植到Linux / Mac OS X的工作(祈)。我已经习惯了,并很喜欢在MSVC简单的内存泄漏检测机制:

After many years of working on a general-purpose C++ library using the Microsoft MSVC compiler in Visual Studio, we are now porting it to Linux/Mac OS X (pray for us). I have become accustomed and quite fond of the simple memory leak detection mechanism in MSVC:

#ifdef DEBUG
    #define _CRTDBG_MAP_ALLOC
    #define NEW   new( _NORMAL_BLOCK, __FILE__, __LINE__)
    #include <stdlib.h>
    #include <crtdbg.h>
#else
    #define NEW   new
#endif

每个内存分配使用这个新的宏完成。每当使用我们的库终止时,任何内存泄漏(尚未解除分配块)的处理被报告在控制台上与在最初分配的存储器中的文件和行#沿

Every memory allocation is done using this NEW macro. Whenever a process using our library terminates, any memory leaks (blocks that have not been de-allocated) are reported on the console along with the file and line # where the memory was originally allocated.

这个是我喜欢的是我没有主动或以其他方式与性能工具运行的部分表明,我要找泄漏。泄漏向我报告在发展的正规课程,每次进程终止。

The part about this that I like is that I don't have to actively "run with performance tool" or otherwise indicate that I am looking for leaks. Leaks are reported to me in the regular course of development, every time a process terminates.

现在,我们正在向GCC的世界里,我发现了内存泄漏检测工具,其中有许多是相当复杂的,要求我明确表明,我在检漏模式。我的IDE是X code和我已经研究过一些分配/泄漏检测工具(如仪器和即MallocDebug),但我承认我没有花时间来让我周围的头完全没有。我不断收到推迟的事实,我实际上是指定我正在寻找,而不是自动提醒它提前泄漏。

Now that we are moving to the GCC world, I find that the memory leak detection tools, many of which are quite sophisticated, require that I explicitly indicate that I'm in leak hunting mode. My IDE is Xcode and I've looked into some of the allocation/leak detection tools (like Instruments and MallocDebug) but I admit I haven't spent the time to get my head around them fully yet. I keep getting put off by the fact that I actually have to specify that I'm looking for a leak ahead of time, instead of being alerted to it automatically.

我用X code 3.2,我听说现在有一个静态分析工具集成漂亮,但同样我没有看过这个。我在寻找什么我的选择有一些想法。有内置到GCC和/或X code可比的机制?有一个简单的第三方库或工具执行,我知道非常基本的功能和爱吗?或者我应该吮吸它,学会做事的新方法?

I am using Xcode 3.2 and I hear that there's now nifty integration with a static analysis tool, but again I haven't looked into this. I'm looking for some idea of what my options are. Is there a comparable mechanism built into GCC and/or Xcode? Is there a simple third-party library or tool that performs the very basic functionality that I know and love? Or should I suck it up and learn the new way of doing things?

推荐答案

您应该看看跨平台的内存泄漏检测,看起来很相似crtdbg.h技术。

You should have a look at "Cross-Platform Memory Leak Detector", looks very similar to the crtdbg.h technique.

这篇关于GCC内存泄漏检测相当于微软crtdbg.h?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆