为什么try块贵吗? [英] Why are try blocks expensive?

查看:179
本文介绍了为什么try块贵吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听说你应该避免的try catch块,如果可能的,因为他们是昂贵的意见。

I've heard the advice that you should avoid try catch blocks if possible since they're expensive.

我的问题是具体涉及.NET平台:为什么try块价格昂贵

My question is specifically about the .NET platform: Why are try blocks expensive?

回应摘要:

有明确两大阵营对这个问题:那些说try块是昂贵的,而那些说也许一个小小的有点

There are clearly two camps on this issue: those that say that try blocks are expensive, and those that say "maybe a tiny little bit".

那些说try块是昂贵的,通常提到的高性价比展开调用堆栈。就个人而言,我不认为用这样的说法 - 特别是阅读有关的异常处理程序是如何在这里存储后。

Those that say try blocks are expensive normally mention the "high cost" of unwinding the call stack. Personally, I'm not convinced by that argument - specially after reading about how exceptions handlers are stored here.

乔恩斯基特坐在也许一个小小的一点的阵营,并写上异常和性能,你可以找到的这里

Jon Skeet sits on the "maybe a tiny little bit" camp, and has written two articles on exceptions and performance which you can find here.

有,我发现非常有趣的一篇文章:它谈到try块的其他的性能影响(不一定是内存或CPU消耗)。彼得里奇提到,他发现try块里面的code不进行优化,因为它会以其他方式是由编译器。你可以阅读有关他的发现<一href="http://msmvps.com/blogs/peterritchie/archive/2007/06/22/performance-implications-of-try-catch-finally.aspx">here.

There was one article that I found extremely interesting: it talked about "other" performance implications of try blocks (not necessarily memory or cpu consumption). Peter Ritchie mentions that he found that code inside try blocks is not optimized as it'd otherwise be by the compiler. You can read about his findings here.

最后,还有从实施的CLR异常的人对这个问题的博客条目。去看看这里克里斯Brumme的文章

Finally, there's a blog entry about the issue from the man that implemented exceptions in the CLR. Go take a look at Chris Brumme's article here.

推荐答案

下面的文章应该阐明这个问题一些轻:

The following articles should shed some light on the subject:

<一个href="http://www.programmersheaven.com/user/pheaven/blog/175-Do-trycatch-blocks-hurt-runtime-performance/">Do尝试... catch块伤的运行时性能?

<一个href="http://msmvps.com/blogs/peterritchie/archive/2007/06/22/performance-implications-of-try-catch-finally.aspx">Performance try / catch语句的意义/终于

这篇关于为什么try块贵吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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