在 Xcode 中编译 i386 和 x86_64 的区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3266902/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 19:33:17  来源:igfitidea点击:

Differences between compiling for i386 vs x86_64 in Xcode?

xcode32bit-64bit

提问by sam

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?

在 Xcode 中编译 Mac 应用程序并将 Active Architecture 设置为 i386 与 x86_64(在主窗口左上角的下拉菜单中选择)有什么区别?在项目的构建设置中,架构选项为标准(32/64 位通用)、32 位通用和 64 位英特尔。实际上,这些是什么意思,人们如何决定?

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?

假设一个目标是 OS X 10.5 及更高版本。我在活动监视器中看到,针对 x86_64 进行编译会导致应用程序使用的内存比针对 i386 编译的应用程序更多。有什么好处?我知道 64 位是“未来”,但考虑到更高的内存使用量,选择 32 位是否有意义?

回答by bbum

32/64-bit Universal -- i386, x86_64, ppc

32/64 位通用 -- i386、x86_64、ppc

32-bit Universal -- i386, ppc

32 位通用 -- i386,ppc

64-bit Intel -- 64 bit Intel only

64 位 Intel -- 仅限 64 位 Intel

ppc64 is no longer supported.

不再支持 ppc64。



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...

由于多种原因,x86_64 二进制文件速度更快;更快的 ABI,更多的寄存器,在许多(大多数和所有新机器)机器上,内核是 64 位的,内核调用速度更快,等等......

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 massiveamount of overhead compare to the 64 bit version.

虽然 64 位的内存开销有一些直接相关,但通常与应用程序数据结构的指针重量直接相关,但请记住,32 位应用程序会拖累所有框架的 32 位版本。如果您的应用程序是系统上唯一的 32 位应用程序,则与 64 位版本相比,它会产生大量开销。

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.

64 位应用程序还可以享受最新最好的 Objective-C ABI;合成的 ivars、非脆弱的 ivars、统一的 C++/ObjC 异常、零成本的 @try 块等……还有许多优化也只能在 64 位中实现。

回答by Rob Napier

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 stanceon the matter:

除非你有理由为 x86_64 编译,否则我建议只为 i386 编译(如果你支持的话,还有 PPC)。阅读苹果对此事的立场

Although 64-bit executables make it easier for you to manage large data sets (compared to memory mapping of large files in a 32-bit application), the use of 64-bit executables may raise other issues. Therefore you should transition your software to a 64-bit executable format only when the 64-bit environment offers a compelling advantage for your specific purposes.

尽管 64 位可执行文件使您可以更轻松地管理大型数据集(与 32 位应用程序中大文件的内存映射相比),但使用 64 位可执行文件可能会引发其他问题。因此,只有当 64 位环境为您的特定目的提供引人注目的优势时,您才应该将您的软件转换为 64 位可执行格式。

回答by Naishta

iOS apps need to run on many different architectures:

iOS 应用程序需要在许多不同的架构上运行:

arm7: Used in the oldest iOS 7-supporting devices[32 bit]
arm7s: As used in iPhone 5 and 5C[32 bit]
arm64: For the 64-bit ARM processor in iPhone 5S[64 bit]

i386: For the 32-bit simulator
x86_64: Used in 64-bit simulator

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

Xcode 基本上模拟 32 位或 64 位的环境,基于有效架构中的设置 - 分别为 i386 或 x86_64

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).

每个架构都需要不同的二进制文件,当您构建应用程序时,Xcode 将为您当前使用的任何内容构建正确的架构。例如,如果您要求它在模拟器中运行,那么它只会构建 i386 版本(或 x86_64 用于 64 位)。