在Quartz2D中是否有使用UIImage或UILabel或NSString的性能或内存开销 [英] Is there any performance or memory overhead using UIImage or UILabel or NSString in Quartz2D

查看:128
本文介绍了在Quartz2D中是否有使用UIImage或UILabel或NSString的性能或内存开销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 UIImage UILabel NSString是否有任何性能或内存开销。 code>

Is there any performance or memory overhead using UIImage or UILabel or NSString in Quartz2D.

如果没有区别,为什么不使用 UIImage UILabel 等。

If there is no difference then why not use UIImage, UILabel etc.

任何人都可以向我发送代码片段不使用 UIImage 绘制图像。

Can any one send me the snippet how to draw image without using UIImage.

提前感谢,
谨慎。

Thanks in advance, Regards.

请更正我,如果您看到任何愚蠢的错误

please correct me if you see any stupid mistake I am new to this, trying to learn it.

推荐答案

标签绘制一个字符串。你不能有一个没有字符串的标签;

A label draws a string. You can't have a label without a string; if you did, what would it draw?

最后我检查了UILabel在内部使用UIWebView,所以你可以做一个更有效的版本。一种方法是使用核心文本;另一种是使用 CATextLayer

Last I checked, UILabel uses UIWebView internally, so you could indeed make a more efficient version. One way would be to use Core Text; the other would be to use a CATextLayer.

对于UIImage,技术上是yes;一个UIImage包装一个CGImage,所以切掉UIImage会节省一些内存。然而,图像使用的存储器的99%是用于图像本身,其像素;这些都包含在CGImage中,而UIImage是微不足道的。

As for UIImage, technically yes; a UIImage wraps a CGImage, so cutting out the UIImage would save some memory. However, 99% of the memory used by an image is for the image itself, its pixels; those are contained within the CGImage, and the UIImage is tiny compared to it. You have better things to spend your time cutting.

不要猜测和/或依赖于优化的一般性,而是使用Instruments找出应用程序正在花费的时间内存开。一旦你知道所有的记忆都要去的坚实证据,你就会知道你可以在哪里找到储蓄。

Rather than guessing and/or relying on generalities for your optimizations, use Instruments to find out exactly what your application is spending its memory on. Once you know with hard evidence where all your memory is going, you'll know where you can look for savings.

封装一般不会增加内存使用;对象是小的,所以如果你创建了很多,你只需要为他们付出很多。而是要缩短他们的生命;不要持有超过您需要的对象(在缓存,集合对象或直接在实例变量/属性中)。

Wrappers generally won't increase memory usage much; objects are small, so you'll only pay a lot for them if you create a lot of them. Look instead to shortening their lifetimes; don't hold onto objects (in caches, collection objects, or directly in instance variables/properties) any longer than you need to.

这篇关于在Quartz2D中是否有使用UIImage或UILabel或NSString的性能或内存开销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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