c# - 任何 CPU - 首选 32 位

标签 c# visual-studio-2012

Any CPU - Prefer 32 bit 选项有什么作用?

虽然我知道 WinRT 不能处理 exe 并且只能运行 Windows 应用商店应用程序,但有几个问题 existStackOverflow问同样的问题并且都引用这个 blog上面写着:

In .NET 4.5 and Visual Studio 11 the cheese has been moved. The default for most .NET projects is again AnyCPU, but there is more than one meaning to AnyCPU now. There is an additional sub-type of AnyCPU, “Any CPU 32-bit preferred”, which is the new default (overall, there are now five options for the /platform C# compiler switch: x86, Itanium, x64, anycpu, and anycpu32bitpreferred). When using that flavor of AnyCPU, the semantics are the following:

  • If the process runs on a 32-bit Windows system, it runs as a 32-bit process. IL is compiled to x86 machine code.
  • If the process runs on a 64-bit Windows system, it runs as a 32-bit process. IL is compiled to x86 machine code.
  • If the process runs on an ARM Windows system, it runs as a 32-bit process. IL is compiled to ARM machine code.

然而,在购买了我的 Surface RT 之后,我创建了一个 Hello World 程序,将其设置为 Any CPU,选中 Prefer 32 Bit 标志,编译并将其复制到我的 Surface。当我运行该程序时,操作系统告诉我它无法运行该程序,我应该像寻找任何 x86/x64 exe 一样去市场看看。显示的确切消息是:“此应用程序无法在你的电脑上运行。若要查找适用于此电脑的应用程序,请打开 Windows 应用商店。”

那么这实际上做了什么,是否有可能在 ARM 上为 Window RT 编译 Any CPU 应用程序?

最佳答案

仅根据您指定的引用,它表明它的含义如下:

  • 如果 CPU 支持 32 位处理,那么最终的机器代码将是 32 位(ARM 或 x86,无所谓)。

  • 如果不是,则机器代码将为 64 位。

在过去,AnyCPU 的意思是“我与平台无关”。这通常意味着您将在 64 位平台上获得 64 位,否则将获得 32 位。

但是,即使在 64 位 CPU 上,您也可能想要 32 位的原因有很多:指针的大小只有一半,因此您使用的内存更少;代码更小,因此更适合缓存等。但是,没有办法强制 CLR 使用 32 位,并且在必要的情况下仍然保留 64 位。

现在,有了 AnyCPU - 首选 32 位,您可以吃蛋糕(必要时支持 64 位),也可以吃蛋糕(尽可能支持 32 位)

注意:如果我没记错的话,Itanium 将是一个只支持 64 位而不是 32 位代码的平台。可能有也可能没有其他人。

免责声明:我不是专家,这只是我在过去 6 个月左右阅读的各种博客文章中的内容

关于c# - 任何 CPU - 首选 32 位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13149905/

相关文章:

c# - 继承自 IReadOnlyCollection 的模拟类

c# - 选择没有特定类的 jQuery First Child

c# - Datagridview 多选不起作用

c# - 在文本框中获取前 10 行和后 10 行 C#

c++ - Visual Studio 2012/2013 语法突出显示错误

search - 在 Visual Studio 的当前命名空间中查找?

visual-studio - 在VS2012输出窗口中滚动到结尾

c# - C# 中的 ReadOnly 与 VB.NET 中的对比

c# - ASP.NET MVC 4 + Ninject MVC 3 = 没有为此对象定义无参数构造函数

c# - 修改 Entity Framework 类型 T4 模板