为什么字体不变? [英] Why is Font immutable?

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

问题描述

字体是不可变的祸患既编程器和GC,因为你需要在每次创建新的实例。

Font being immutable distresses both the programmer and the GC, because you need to create a new instance every time.

为什么[字体不可变的引用类型呢?

Why is Font an immutable reference type then?

推荐答案

它简化了从渲染系统的使用。

It simplifies the usage from the render system.

如果该框架是让字体是可变的,那就需要检测的变化,返工它是如何渲染发生定期。由于字体创建的本地资源,保持这个不可改变防止系统担心不必重复基础上,在内部重新把手。

If the framework were to allow Font to be mutable, it would need to detect changes, and rework how it's rendering happens on a regular basis. Since Font creates a native resource, keeping this immutable prevents the system from worrying about having to recreate handles internally on a repeated basis.

另外,我不同意在困境条款给程序员。通过使字体不可变的,这使得它更加明显,当用户创建一个Font对象发生了什么。如果你想要一个新的字体,你需要创建一个新的字体对象,这反过来又创造新的本地字体资源。制作字体不变使得它更清楚发生了什么 - 你就不太可能意外地创建一个性能问题

Also, I disagree in terms of "Distress to the programmer". By making Font immutable, it makes it more obvious what is happening when the user creates a Font object. If you want a new Font, you need to create a new Font object, which in turn creates new native font resources. Making Font immutable makes it more clear what is happening - you're less likely to create a performance problem accidentally.

是字体可变的,这将是你不太明显创建手柄多次被评为你改变字体的属性。

Were Font mutable, it would be less obvious that you were creating handles repeatedly as you changed your Font properties.

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

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