使用CGFloat和float有什么区别? [英] What's the difference between using CGFloat and float?

查看:274
本文介绍了使用CGFloat和float有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我倾向于使用CGFloat在所有的地方,但我不知道如果我得到一个无意义的性能打击这一点。 CGFloat似乎是比float更重的东西,对吧?

解决方案

如@weichsel所说,CGFloat只是一个typedef对于 float double 。你可以通过Command看到自己 - 双击Xcode中的CGFloat - 它将跳转到定义typedef的CGBase.h头文件。同样的方法也用于NSInteger和NSUInteger。



引入这些类型使得更容易编写32位和64位的代码,而不需要修改。但是,如果你需要的是你自己的代码中的 float precision,你仍然可以使用 float 会减少你的内存占用。



我建议你投资所需的适当时间使你的应用程序64位清洁,并尝试运行它,因为大多数Macs现在有64位的CPU和Snow Leopard是完全64位,包括内核和用户应用程序。 Apple的 64位可可转换指南是一种有用的资源。 p>

I tend to use CGFloat all over the place, but I wonder if I get a senseless "performance hit" with this. CGFloat seems to be something "heavier" than float, right? At which points should I use CGFloat, and what makes really the difference?

解决方案

As @weichsel stated, CGFloat is just a typedef for either float or double. You can see for yourself by Command-double-clicking on "CGFloat" in Xcode — it will jump to the CGBase.h header where the typedef is defined. The same approach is used for NSInteger and NSUInteger as well.

These types were introduced to make it easier to write code that works on both 32-bit and 64-bit without modification. However, if all you need is float precision within your own code, you can still use float if you like — it will reduce your memory footprint somewhat. Same goes for integer values.

I suggest you invest the modest time required to make your app 64-bit clean and try running it as such, since most Macs now have 64-bit CPUs and Snow Leopard is fully 64-bit, including the kernel and user applications. Apple's 64-bit Transition Guide for Cocoa is a useful resource.

这篇关于使用CGFloat和float有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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