在32位应用程序中使用64位整数可以吗? [英] Is it ok to use 64bit integers in a 32bit application?

查看:228
本文介绍了在32位应用程序中使用64位整数可以吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到在C和C ++中,我们可以使用int64_t或简单地使用long long.

I notice in C and C++, we can use int64_t, or simply a long long.

如果我使用这些类型编译 32bit代码,我会在 64bit 和/或 32bit机器上遇到任何性能问题吗?

If I compile 32bit code using these types, will I suffer any performance issues on 64bit and/or 32bit machines?

除了节省一些RAM外,我是否有理由只使用int?
毕竟,64位int在存储大量数字时要有用得多.

Aside from saving some RAM, would I ever have a reason to just use int?
After all, 64bit ints are far more useful in storing large numbers.

推荐答案

如果我使用这些类型编译32位代码,我会在64位和/或32位计算机上遇到性能问题吗?

If I compile 32bit code using these types, will I suffer any performance issues on 64bit and/or 32bit machines?

您的编译器可能需要生成一些机器代码指令才能对64位值执行操作,从而使这些操作速度降低了数倍.如果这可能是一个问题,则需要进行一些基准测试,以评估对具有实际数据的特定程序的影响.在32位或64位计算机上执行32位可执行文件时,就会出现该问题.

Your compiler may need to generate several machine code instructions to perform operations on the 64 bit values, slowing down those operations by several times. If that might be a concern, you'd want to do some benchmarking to assess the impact on a particular program with realistic data. That issue exists where you're executing the 32 bit executable on a 32 or 64 bit machine.

我是否有理由只使用int?

除了性能和内存使用之外,有时还需要使用int,因为您使用的其他API/流等都使用int.如果int显然足够,那么使用int也有微不足道的文档价值,否则其他程序员可能会浪费时间想知道为什么您会不屑一顾地使用long long.

Aside from performance and memory usage, there's occasionally reason to use ints because other APIs/streams etc. that you work with use int. There's also subtle documentary value in using int if it's clearly adequate, otherwise other programmers may waste time wondering why you'd gone out of your way to use a long long.

毕竟,64位整数在存储大量数字时更加有用.

After all, 64bit ints are far more useful in storing large numbers.

存储大量非常有用得多-当然-但这很少需要.如果您要存储的是一年或某人的年龄,那么拥有64位就没有什么特别的意义了.

Far more useful in storing very large numbers - sure - but that's relatively rarely needed. If you're storing something like a year or someone's age, there's just no particular point in having 64 bits.

这篇关于在32位应用程序中使用64位整数可以吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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