zoukankan      html  css  js  c++  java
  • 【.NET 4.5】新增的 Prefer 32-bit target platform

    这本来是一个很小的feature并且也没有什么模糊的地方,关键是VS把这个设置成了默认值,当默认为Any CPU的时候,application会被编译成32-bit mode.

    下边是我遇到的问题,在64-bit OS上,使用VS2013创建基于.net 4.5的console 工程,代码如下:

                // SoftwareWow6432Nodemytest default value is 0
                var x86path =  @"SoftwareWow6432Nodemytest";
                // Softwaremytest default value is 1
                var x64path = @"Softwaremytest";
                Console.WriteLine(Registry.LocalMachine.OpenSubKey(x86path).GetValue("").ToString()); // output is 0
                Console.WriteLine(Registry.LocalMachine.OpenSubKey(x64path).GetValue("").ToString()); // output is 0

    Console.WriteLine(Registry.LocalMachine.OpenSubKey(x64path).GetValue("").ToString()); 希望的输出是1,最终输出0. 为什么呢?答案在MSDN中:

    • anycpu (default) compiles your assembly to run on any platform. Your application runs as a 64-bit process whenever possible and falls back to 32-bit when only that mode is available.

    • anycpu32bitpreferred compiles your assembly to run on any platform. Your application runs in 32-bit mode on systems that support both 64-bit and 32-bit applications. You can specify this option only for projects that target the .NET Framework 4.5.

    • x86 compiles your assembly to be run by the 32-bit, x86-compatible common language runtime.

    http://msdn.microsoft.com/en-us/library/zekwfyz4.aspx

    很显然,anycpu32bitpreferred 就是把application编译成了一个可以在ARM/X64/X86/Itanium下运行的x86 application。这一点算是一个增强,但不应该是一个默认值。

    • ------------------------
    • 64-bit and 32-bit tips:
    1. On a 64-bit Windows system, both the 32-bit and 64-bit versions of system DLLs are stored. The 64-bit DLLs are in C:WindowsSystem32, and the 32-bit DLLs are in C:WindowsSysWOW64.
    2. When a 32-bit process opens a file in C:Program Files, it actually reads/writes to C:Program Files (x86).
    3. There are separate views of (most of) the registry for 32-bit and 64-bit applications. You can change the 64-bit registry location and it wouldn’t be visible to 32-bit applications.
  • 相关阅读:
    队列的链式存储结构实现
    堆栈的链式存储实现
    使用C#改变windows系统本地时间
    oracle 多数值录入校验(分隔符“/”)
    oracle中in和exists的区别
    redis安装 windows版(图形化安装)
    Oracle 返回结果集
    饿了么4年 + 阿里2年:研发路上的一些总结与思考
    Oracle 获取各类时间
    Oracle表中已有数据,修改字段长度
  • 原文地址:https://www.cnblogs.com/xixifusigao/p/3542547.html
Copyright © 2011-2022 走看看