11

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?

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Mimefilt
  • 640
  • 8
  • 20
  • 3
    this may help - http://stackoverflow.com/questions/3102765/net-3-5-web-application-porting-to-64bit-potential-issues – Jagmag Aug 22 '10 at 08:24
  • 1
    possible duplicate of [64 bits stuff for C# development](http://stackoverflow.com/questions/1889941/64-bits-stuff-for-c-development) – Hans Passant Aug 22 '10 at 08:52

4 Answers4

30

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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Chris Schmich
  • 27,532
  • 5
  • 71
  • 93
3

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.

Avlin
  • 490
  • 4
  • 18
3

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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Incognito
  • 16,037
  • 9
  • 50
  • 72
0

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!

Eric Aya
  • 68,765
  • 33
  • 165
  • 232