我正在编写一个应用程序,我想知道是否应该在32位模式或64位模式下编译它。 该程序不使用任何64位类型,并且不访问超过4千兆字节的内存(我并不计划访问那么多内存)。 我在32位模式下使用64位模式时可以看到的唯一优势是64位模式允许访问更多寄存器,但在大多数情况下使用32位模式而不是64位模式必须有一些好处没有使用64位功能(除了较小的指令和指针,因为我不担心我的程序溢出缓存)。 使用32位是否有一些好处,例如更快的指令或更少的能耗,这应该导致我编译为32位。 谢谢。
I'm writing an app, and I am wondering whether I should compile it in 32-bit mode or 64-bit mode. The program doesn't use any 64-bit types and doesn't access over 4 gigabytes of memory (and I don't plan on it ever accessing that much memory). The only advantage that I can see in using 64-bit mode over 32-bit mode is that 64-bit mode allows more registers to be accessed, but there must be some benefit to using 32-bit mode over 64-bit mode when most of the 64-bit features are not being used (other than smaller instructions and pointers, since I am not worried about my program overflowing the cache). Is there some benefit to using 32-bit such as faster instructions or less energy consumption that should lead me to compiling for 32-bit instead. Thank you.
最满意答案
取决于应用程序类型。
正如其他人所提到的,32位平台被认为已被弃用,而在64位平台上运行32位应用程序会产生一些开销。 此外,正如您所提到的,编译器可以访问更多寄存器和更高级的指令集。
OTOH存在这样的情况:由于较小的本机指针大小,为32位编译的代码将具有显着的优势。
例如,我有一个带有“算法”代码的应用程序,它处理存储在具有交叉指针的复杂数据结构中的大数据集。 为32位平台编译的相同应用程序具有明显更小的内存占用,并且运行速度更快。
因此,如果您的应用程序不接近32位限制,则使用具有本机指针的复杂数据结构,并且性能至关重要 - 32位可能是一种方法。 否则我建议切换到64位。
Depends on the application type.
As others mentioned, 32-bit platforms are considered deprecated, and running 32-bit applications on 64-bit platforms imposes some overhead. In addition, as you mentioned, there are more registers accessible to the compiler and more advanced instruction set.
OTOH there are scenarios where code compiled for 32-bit would have a significant advantage, due to the smaller native pointers size.
For instance I have an application with "algorithmic" code, which deals with large data set stored in complex data structures with cross-pointers. The same application compiled for 32-bit platform has significantly smaller memory footprint, and runs considerably faster.
So that if your application doesn't approach the 32-bit limitation, works with complex data structures with native pointers, and the performance is critical - 32-bit may be a way to go. Otherwise I'd recommend switching to 64-bit.
更多推荐
发布评论