- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我看到了下面的宏,
#ifdef _DEBUG
#define new DEBUG_NEW
#UNDEF THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
上述宏的用法是什么?
谢谢
最佳答案
DEBUG_NEW 只是一个 MACRO,通常定义为:
#define DEBUG_NEW new(__FILE__, __LINE__)
#define new DEBUG_NEW
因此,无论您在哪里使用 new
,它都可以跟踪文件和行号,这些文件和行号可用于定位程序中的内存泄漏。
而__FILE__
、__LINE__
都是predefined macros在您使用它们的地方分别评估文件名和行号!
阅读下面的文章,它非常漂亮地解释了将 DEBUG_NEW 与其他有趣的宏一起使用的技术:
A Cross-Platform Memory Leak Detector
来自 Wikpedia ,
Debug_new refers to a technique in C++ to overload and/or redefine operator new and operator delete in order to intercept the memory allocation and deallocation calls, and thus debug a program for memory usage. It often involves defining a macro named DEBUG_NEW, and makes new become something like new(_FILE_, _LINE_) to record the file/line information on allocation. Microsoft Visual C++ uses this technique in its Microsoft Foundation Classes. There are some ways to extend this method to avoid using macro redefinition while still able to display the file/line information on some platforms. There are many inherent limitations to this method. It applies only to C++, and cannot catch memory leaks by C functions like malloc. However, it can be very simple to use and also very fast, when compared to some more complete memory debugger solutions.
关于c++ - DEBUG_NEW 和 __FILE__ 有什么用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5421754/
我是 Django 项目的初学者。Django 项目的 settings.py 文件包含这两行: BASE_DIR = os.path.dirname(os.path.dirname(os.path.
如何获取我的 Crystal 脚本的编译版本以获取它自己的 __FILE__。这是一个例子。我有一个名为 ~/test.cr 的文件,其中包含以下内容: puts __FILE__ 我通过 Cryst
这个问题已经有答案了: What's the difference between __PRETTY_FUNCTION__, __FUNCTION__, __func__? (5 个回答) 已关闭 6
有没有更好的方法来打印 __file__ 而无需扩展名? import os print os.path.splitext(__file__)[0] 最佳答案 您可以使用 string.split,但
在线程中的if语句中使用__file__时出现错误,代码如下: import os from threading import Thread def cur_dir(): current_di
如果我在下面这样做: #include int main() { printf ("%s\n",__FILE__); return 0; } >gcc cfilename.c >./a.out
我知道在 Ruby 中 __FILE__ 指的是当前文件,但是在创建这样的路径时它指的是什么,为什么需要它作为 expand_path 的第二个参数? set :views, File.expand_
我有十几个脚本,我在其中重复这个 # caller.py THIS_FILE_DIR = os.path.dirname(os.path.realpath(__file__)) relative_pa
我想在我的模块 m 中定义一个效用函数 f() 这样 如果在/foo/a.py中调用m.f(),它返回/foo/a.py 如果在/bar/baz/b.py中调用m.f(),它返回/bar/baz/b.
我正在使用 WAMP 并在 www 目录中有一个开发站点。我想使用 dirname(__FILE__) 来定义服务器根目录的路径。 目前我使用的配置文件包含: define('PATH', dirna
我正在使用 DPRINTF(ERROR_LEVEL,"ERROR: error found at file: %s line: %d",__FILE__,__LINE__); 它像这样打印 ERROR
我正在使用 PHP 解压缩 PHP 应用程序本身的更新。这是通过从更新服务器抓取一个 zip 文件,将其解压缩,然后递归地将解压缩的文件移动到应用程序当前存在的文件上来完成的。 问题是下次我去使用该应
我正在尝试编写一种可以在使用文件完整路径的扩展类中使用的方法。但是,当我使用 __FILE__ 时,我只会返回定义继承方法的类的路径。这是一个示例: foo.php class foo { p
这个问题在这里已经有了答案: What method can I use instead of __file__ in python? (2 个答案) 关闭 5 年前。 情况是: python 嵌入
我发现我经常使用这种模式: os.path.join(os.path.dirname(__file__), file_path) 所以我决定在一个包含许多此类小实用程序的文件中放入一个函数: def
C 中可用的标准预定义宏 __FILE__ 显示文件的完整路径。有什么办法可以缩短路径吗?我的意思是代替 /full/path/to/file.c 我明白了 to/file.c 或 file.c 最佳
我有来自 Codeigniter index.php 的以下代码 我的理解是, 如果 $system_folder(在本例中为 CIcore_1_7_1)中字符串位置的 / 为 false,如果 re
谁能告诉我这两种方法中的任何一种是否比另一种有优势,为什么? $mydir = ABSPATH.'/wp-content/themes/mytheme/images'; $mydir = dirnam
我在将一些东西从 Solaris 移植到 Linux 时遇到的一个问题是 Solaris 编译器在预处理期间将宏 __FILE__ 扩展为文件名(例如 MyFile.cpp),而 Linux 上的 g
__FILE__表示当前所在文件的绝对路径包括文件名,dirname(__FILE__)表示当前文件的绝对路径,basename(__FILE__)表示当前文件的文件名称,dirname(__FIL
我是一名优秀的程序员,十分优秀!