加快反射API与委托的.NET / C# [英] Speeding up Reflection API with delegate in .NET/C#

查看:137
本文介绍了加快反射API与委托的.NET / C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

帖子有评论如果你需要调用该方法多次,使用反射一旦找到它,然后将其分配给一个委托,然后调用委托。

  • 如何以及为什么会发生这种代理工作得更快?任何人都可以有一些例子吗?
  • 我可以把这个缓存?如果是这样,有没有比这个缓存方法与委托?任何其他方法
  • How and why does this delegate work faster? Can anyone has some example?
  • Can I call this caching? If so, are there any other method than this caching method with delegate?

我想出了使用委托的例子 <一个href="http://stackoverflow.com/questions/6430835/example-speeding-up-reflection-api-with-delegate-in-net-c">here.

推荐答案

一个的委托只是一个指针的函数。如果您使用的是反射(所有)一般存在大量的开销与它相关联。通过寻找这种方法解决一次分配的地址,你的代理变量,你实际上是其高速缓存。

A delegate is simply a pointer to a function. If you're using reflection (at all) there is generally a lot of overhead associated with it. By finding this methods address once and assigning that address to your delegate variable, you are in effect caching it.

所以,这不是委托式的作品更快,它只是你在计算一次,使用它多次,授予你的速度增加。

So, it's not the "delegate" type that works faster, it's just that you're "computing" once and "using" it multiple times that grants you the speed increase.

这篇关于加快反射API与委托的.NET / C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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