32 位和 64 位 .NET (4) 应用程序之间的差异 [英] Differences between 32 and 64-bit .NET (4) applications

查看:40
本文介绍了32 位和 64 位 .NET (4) 应用程序之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

32 位和 64 位 .NET (4) 应用程序之间有什么区别?

What are the differences between 32 and 64-bit .NET (4) applications?

通常 32 位应用程序在 64 位机器上运行时会出现问题,反之亦然.我知道我可以将整数声明为 int32 和 int64(当然 32 位系统上的 int64 会产生问题).为 32 位或 64 位或同时兼容 32 位和 64 位的应用程序编程之间还有其他区别吗?

Often 32-bit applications have problems running on 64-bit machines and conversely. I know I can declare an integer as int32 and int64 (certainly int64 on 32-bit systems make problems). Are there other differences between programming an 32 OR 64-bit or a both 32 AND 64-bit compatible application?

推荐答案

一些差异:

  1. 32 位和 64 位应用程序只能加载相同位数的 DLL.如果您的平台目标是任何 CPU"并且您引​​用或 P/Invoke 32 位本机 DLL.当您的任何 CPU"程序在 64 位机器上运行时就会出现问题,因为您的应用程序作为 64 位进程运行.当它尝试加载 32 位本机 DLL 依赖项时,它会抛出异常 (BadImageFormatException) 并可能崩溃.

  1. 32-bit and 64-bit applications can only load DLLs of the same bitness. This can be an issue for managed projects if your platform target is "Any CPU" and you reference or P/Invoke 32-bit native DLLs. The issue arises when your "Any CPU" program runs on a 64-bit machine, since your application runs as a 64-bit process. When it tries to load the 32-bit native DLL dependency, it will throw an exception (BadImageFormatException) and likely crash.

还有文件系统和注册表问题.尝试从 C:Program Files 读取的 WOW64 进程将最终会被重定向到 C:Program Files (x86),除非它首先禁用 Windows 文件系统重定向(请参阅 Wow64DisableWow64FsRedirection).对于 Windows 7 之前的 Windows 版本,也存在类似于上述文件系统重定向问题的注册表反射问题.MSDN 文章注册表反射 解释得很好.

There are also filesystem and registry issues. A WOW64 process that tries to read from C:Program Files will end up getting redirected to C:Program Files (x86) unless it first disables Windows filesystem redirection (see Wow64DisableWow64FsRedirection). For versions of Windows before Windows 7, there were also registry reflection issues that were similar to the filesystem redirection issues mentioned above. The MSDN article Registry Reflection explains it well.

特定于平台的类型,例如 IntPtr 将具有不同的大小.这可能是假定大小固定(序列化、编组)的代码中的问题.

Platform-specific types like IntPtr will have different sizes. This could be an issue in code that assumes a fixed size (serialization, marshaling).

GAC.对于我的系统,它们位于 C:WindowsMicrosoft.NETassemblyGAC_32C:WindowsMicrosoft.NETassemblyGAC_64.

There are separate physical directories for the 32- and 64-bit files in the GAC. For my system, they are at C:WindowsMicrosoft.NETassemblyGAC_32 and C:WindowsMicrosoft.NETassemblyGAC_64.

32 位和 64 位应用程序的虚拟地址空间大小不同.对于 32 位应用程序,大小为 2GB(默认)或 3GB(使用 4GT 已启用).对于 64 位应用程序,大小为 8 TB.32 位地址空间对于非常大的应用程序来说可能是一个限制.

The virtual address space size of 32- and 64-bit applications is different. For 32-bit applications, the size is either 2 GB (default) or 3 GB (with 4GT enabled). For 64-bit applications, the size is 8 TB. The 32-bit address space can be a limitation for very large applications.

有点晦涩,但很多进程间 Win32 调用不会在 32 位和 64 位进程之间工作.例如,尝试调用 时,32 位进程可能会失败ReadProcessMemory 在 64 位进程上.WriteProcessMemoryEnumProcessModules 和许多类似的方法也是如此.如果您尝试使用 System.Diagnostics.Process.Modules API.

A little more obscure, but a lot of interprocess Win32 calls won't work between a 32- and 64-bit process. For example, a 32-bit process can fail when trying to call ReadProcessMemory on a 64-bit process. The same goes for WriteProcessMemory, EnumProcessModules, and a lot of similar methods. This can be seen in C# applications if you try to enumerate the modules of a 64-bit application from a 32-bit application using the System.Diagnostics.Process.Modules API.

这篇关于32 位和 64 位 .NET (4) 应用程序之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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