如何为WPF属性系统的经济性? [英] How is the WPF property system economical?

查看:101
本文介绍了如何为WPF属性系统的经济性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人说,WPF的设计者已经使得经济的或更高的性能。是否有人可以用,使WPF属性系统更经济的引擎盖下会发生什么一个例子解释一下吗?

It is said that the designers of WPF have made it economical or higher performance. Can someone please explain with an example of what happens under the hood that makes the WPF property system more economical?

推荐答案

您可能参照事实依赖属性是比正常CLR属性便宜

You are probably referring to the fact that Dependency Properties are "cheaper" than normal CLR properties.

在几句:

依赖属性正在使用的仅当设置对象的对属性值分配内存。相比之下,一个标准的CLR属性值存储为内场的类的每一个对象,其中属性定义的,即使所有这些对象都属性设置为默认值。

Dependency properties are implemented using sparse data structures that only allocate memory for the property value if it is set on an object. In contrast, a standard CLR property value is stored as a field inside every object of the class in which the property is defined, even if all of these objects have the property set to its default value.

因此,举例来说,如果我们有型的100 CLR性能100个对象 INT 每次,那么我们使用10000 INT 值得的内存,即使所有这些具有相同的默认值(0)。

So for example, if we have 100 objects with 100 CLR properties of type int each, then we are using 10000 ints worth of memory even if all of those have the same default value (0).

如果该属性是一个依赖属性相反,我们将不使用任何额外的内存都:WPF不需要记住任何财产的价值,因为它知道你是不是更改默认

If the property were a dependency property instead, we would not be using any additional memory at all: WPF does not need to remember the value of any property since it knows that you didn't change it from the default.

当然,上面是比较简单化的解释,不包括在CLR性能依赖属性的所有优点,但它应该解释一下移民拥有更高的性能的声明充分。

Of course the above is rather a simplistic explanation and does not cover all the advantages of dependency properties over CLR properties, but it should explain the "DPs have higher performance" statement adequately.

这篇关于如何为WPF属性系统的经济性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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