编译为32位或64位(Compile for 32 bit or 64 bit)

编程入门 行业动态 更新时间:2024-10-24 05:23:08
译为32位或64位(Compile for 32 bit or 64 bit)

我正在编写一个应用程序,我想知道是否应该在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.

更多推荐

本文发布于:2023-08-07 19:59:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465539.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:译为   Compile   bit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!