在 Xcode 中编译 i386 与 x86_64 之间的差异?
在 Xcode 中将 Active Architecture 设置为 i386 与 x86_64(在主窗口左上角的下拉列表中选择)编译 Mac 应用程序之间有什么区别?在项目的“构建”设置中,“架构”选项为“标准”(32/64 位通用)、“32 位通用”和“64 位 Intel”。实际上,这些意味着什么以及如何决定?
假设目标是 OS X 10.5 及更高版本。我在活动监视器中看到,针对 x86_64 进行编译会导致应用程序使用比针对 i386 编译的应用程序更多的内存。优点是什么?我知道 64 位是“未来”,但考虑到更高的内存使用量,选择 32 位是否有意义?
What are the differences between compiling a Mac app in Xcode with the Active Architecture set to i386 vs x86_64 (chosen in the drop down at the top left of the main window)? In the Build settings for the project, the Architecture options are Standard (32/64-bit Universal), 32-bit Universal, and 64-bit Intel. Practically, what do these mean and how does one decide?
Assume one is targeting OS X 10.5 and above. I see in the Activity Monitor that compiling for x86_64 results in an app that uses more memory than one compiled for i386. What is the advantage? I know 64-bit is "the future", but given the higher memory usage, would it make sense to choose 32-bit ever?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
除非您有理由针对 x86_64 进行编译,否则我建议您只针对 i386 进行编译(如果您支持的话,还可以针对 PPC 进行编译)。阅读 苹果对此事的立场:
Unless you have a reason to compile for x86_64, I recommend just compiling for i386 (and PPC if you support that). Read Apple's stance on the matter:
iOS 应用程序需要在许多不同的体系结构上运行:
Xcode 基本上根据有效体系结构中设置的内容模拟 32 位或 64 位环境 - 分别为 i386 或 x86_64
每个体系结构都需要不同的二进制文件,当您构建应用程序时 Xcode 会为您当前正在使用的任何内容构建正确的架构。例如,如果您要求它在模拟器中运行,那么它只会构建 i386 版本(或 64 位的 x86_64)。
iOS apps need to run on many different architectures:
Xcode basically emulates the environment of 32 bit or 64 bit based on what is set in the Valid Architecture - i386 or x86_64 respectively
Every architecture requires a different binary, and when you build an app Xcode will build the correct architecture for whatever you’re currently working with. For instance, if you’ve asked it to run in the simulator, then it’ll only build the i386 version (or x86_64 for 64-bit).
32/64 位通用 - i386、x86_64、ppc
32 位通用 - i386、ppc
64 位 Intel -
不再支持仅 64 位 Intel ppc64。
由于多种原因,x86_64 二进制文件速度更快;更快的 ABI、更多的寄存器,在许多(大多数和所有新机器)机器上,内核都是 64 位和 64 位。内核调用速度更快,等等...
虽然 64 位有一些内存开销,通常与应用程序数据结构的指针重量直接相关,但请记住,32 位应用程序会拖入 32 位版本所有框架。如果您的应用程序是系统上唯一的 32 位应用程序,那么与 64 位版本相比,它将产生大量的开销。
64 位应用程序还可以享受最新、最好的 Objective-C ABI;合成的 ivars、非脆弱的 ivars、统一的 C++/ObjC 异常、零成本 @try 块等...还有许多优化也只能在 64 位中实现。
32/64-bit Universal -- i386, x86_64, ppc
32-bit Universal -- i386, ppc
64-bit Intel -- 64 bit Intel only
ppc64 is no longer supported.
x86_64 binaries are faster for a number of reasons; faster ABI, more registers, on many (most & all new machines) machines the kernel is 64 bit & kernel calls are faster, etc.etc.etc...
While 64 bit has a bit of memory overhead directly related, generally, to how pointer heavy your app's data structures are, keep in mind that 32 bit applications drag in the 32 bit versions of all frameworks. If yours is the only 32 bit app on the system, it is going to incur a massive amount of overhead compare to the 64 bit version.
64 bit apps also enjoy the latest and greatest Objective-C ABI; synthesized ivars, non-fragile ivars, unified C++/ObjC exceptions, zero-cost @try blocks etc... and there are a number of optimizations that are only possible in 64 bit, too.