GCC memory leak detection equivalent to Microsoft crtdbg.h?(GCC 内存泄漏检测相当于 Microsoft crtdbg.h?)
问题描述
在 Visual Studio 中使用 Microsoft MSVC 编译器开发通用 C++ 库多年后,我们现在将其移植到 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 是 Xcode,我已经研究了一些分配/泄漏检测工具(如 Instruments 和 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.
我正在使用 Xcode 3.2,我听说现在有一个与静态分析工具的漂亮集成,但我还没有研究过这个.我正在寻找一些关于我的选择的想法.GCC 和/或 Xcode 中是否有类似的机制?是否有一个简单的第三方库或工具可以执行我所了解和喜爱的非常基本的功能?还是我应该接受它并学习新的做事方式?
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?
推荐答案
你应该看看 "Cross-Platform Memory Leak Detector",看起来与 crtdbg.h 技术非常相似.
You should have a look at "Cross-Platform Memory Leak Detector", looks very similar to the crtdbg.h technique.
这篇关于GCC 内存泄漏检测相当于 Microsoft crtdbg.h?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:GCC 内存泄漏检测相当于 Microsoft crtdbg.h?
基础教程推荐
- 从 std::cin 读取密码 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01