32位和64位.NET应用程序的区别(4)

发布于 2024-09-15 02:27:52 字数 179 浏览 5 评论 0原文

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

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

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

凉栀 2024-09-22 02:27:52

一些区别:

  1. 32 位和 64 位应用程序只能加载相同位数的 DLL。如果您的平台目标是“任何 CPU”并且您引​​用或 P/Invoke<,这对于托管项目来说可能是一个问题/a> 32 位本机 DLL。当您的“任何 CPU”程序在 64 位计算机上运行时,就会出现问题,因为您的应用程序作为 64 位进程运行。当它尝试加载 32 位本机 DLL 依赖项时,它将引发异常 (BadImageFormatException)并可能崩溃。

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

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

  4. GAC 中的 32 位和 64 位文件有单独的物理目录。对于我的系统,它们位于 C:\Windows\Microsoft.NET\Assembly\GAC_32C:\Windows\Microsoft.NET\Assembly\GAC_64

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

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

Some differences:

  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.

  2. 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.

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

  4. There are separate physical directories for the 32- and 64-bit files in the GAC. For my system, they are at C:\Windows\Microsoft.NET\assembly\GAC_32 and C:\Windows\Microsoft.NET\assembly\GAC_64.

  5. 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.

  6. 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.

下雨或天晴 2024-09-22 02:27:52

一般来说,我认为托管代码不应该有任何问题。

潜在的问题可能来自非托管代码。比如因为32位和64位系统中变量大小不同,指针不同等等。比如C/C++中int变量的大小取决于系统。至于已经提到的托管代码, WoW 可以处理它。

In general, I think you should not have any problems with managed code.

Potential problems can come from unmanaged code. For example, because variable sizes are different in 32-bit and 64-bit systems, pointers are different, etc. For example, the size of the int variable in C/C++ depends on the system. As for managed code as already mentioned, WoW can handle that.

太阳男子 2024-09-22 02:27:52

x64 托管代码将使用流式 SIMD 扩展 (SSE) 进行双精度/浮点计算,而不是 x87 <使用 x86 托管代码时,a href="https://en.wikipedia.org/wiki/Floating-point_unit" rel="nofollow noreferrer">浮点单元 (FPU)。

x64 managed code will use Streaming SIMD Extensions (SSE) for double/float computation instead of x87 Floating Point Unit (FPU) when using x86 managed code.

数理化全能战士 2024-09-22 02:27:52

除了其他答案之外,我还想补充一件事:我们可以在64位上运行32位系统的软件,但反之则不可能!

In addition to other answers, I would like to add one more thing: we can run software of 32-bit system on 64 but conversely is not possible!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文