iPhone/iPad:多次调用 NSLog() 是否会影响应用程序性能或内存?

发布于 2024-12-05 13:32:21 字数 127 浏览 2 评论 0原文

我想知道多次 NSLog() 调用是否会影响应用程序性能或内存。 有谁知道这样的事情吗?

我想在我的应用程序中的每个函数中放置一个 NSLog() 调用(很多),以便我可以看到 崩溃后记录并跟踪问题。

谢谢。

I would like to know if having many NSLog() calls affects app performance or memory.
Does anyone know about such thing?

I want to put an NSLog() call in every function in my app (which is a lot) so that I can see
crash logs after and trace problems.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

桜花祭 2024-12-12 13:32:21

是的。所以我在我的 pch 文件中定义了它。

#ifdef DEBUG
#   define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#   define DLog(...)
#endif

// ALog always displays output regardless of the DEBUG setting
#define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);

我没有使用 NSLog,而是使用 DLog 和 ALog。

(注意或版权:我很久以前从其他一些我不记得的SO帖子中得到了这个代码。从我的代码片段库中再次粘贴它)

Yes. So I define this in my pch file.

#ifdef DEBUG
#   define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#   define DLog(...)
#endif

// ALog always displays output regardless of the DEBUG setting
#define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);

Instead of using NSLog, I use DLog and ALog.

(Note or copyrights: I got this code long long ago from some other SO post which I don't remember. Pasting it again from my snippet library)

美羊羊 2024-12-12 13:32:21

“取消定义”NSLog 的另一个简单解决方案:

在 .pch 文件中

#ifndef DEBUG
#define NSLog(...) /* */
#endif

Another easy solution to 'undefine' NSLog

In .pch file:

#ifndef DEBUG
#define NSLog(...) /* */
#endif
浪漫之都 2024-12-12 13:32:21

是的,它会降低性能,特别是如果该函数应该花费很短的时间,NSLog(这是一个 I/O 过程)将使它花费比预期更多的时间。

Yes, it slows down the performance, especially if the function is supposed to take very short time, the NSLog (which is an I/O process) will make it take more time than expected.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文