What are the consequences of programming in 32-bit or 64-bit?

Would only memory capacity be limited to 4 GB in 32 bits?

Do I need to have specific concerns?

I know what's different about C, I want to know about C#.

Author: Maniero, 2017-04-26

3 answers

You should know that the 32-bit pointer has 4 bytes and in 64-bit architecture it has 8 bytes. This has profound internal changes in .NET.

The memory consumption of all objects that have pointers will be higher. Although C# does not have free pointers (except in context unsafe) there are opaque pointers in everything that is a type by reference, since the Pointer is the mechanism of getting the reference.

The consumption of the object itself increases even if it has no members by reference. Every object in the heap needs two CPU words , one of them is a pointer to the type of that object that is important for reflection, memory management by the garbage collector and polymorphism. The other word has multiple functions and can be a pointer as well, and should have the same size as the previous word up because it issues alignment.

Then it becomes obvious that having the Pointer, This header that every object owns will be higher.

Besides this the type IntPtr it has its size changed since it is pointer.

 13
Author: Maniero, 2020-12-01 12:10:00

In addition to memory, there are other sim:

  • DLLs are loaded in applications with equivalent bits. If you try to load a 32-bit DLL into a 64-bit application, the {[0 exception is thrown]}
  • platform-specific types, IntPtr for example, have different sizes.
  • interprocess communication can have problems when done between 32-bit and 64-bit processes. For example, ReadProcessMemory might fail when a 32-bit process tries to read from a process 64-bit.
  • There is also the situation of Registry Reflection, explained in MSDN.

You will encounter problems depending on the complexity of the application.

 7
Author: Rodrigo Nogueira, 2017-04-26 14:21:58

One more piece of information to complement Rodrigo and Maniero's answers.

If you compile the application as 64-bit, it will not run on machines with 32-bit (or less) processors.

Since we haven't seen this type of machine for a long time (Windows XP already had 64-bit versions in the middle of the Jurassic period), this would only be a problem if you tried to run an application on a museum piece. But I think it's worth mentioning, either way.

Now, seriously, the only practical application I see for 32-bit compilation is to update DLLs from 32-bit applications-and these still exist and are very common. If you are going to update a DLL from such an application, you have to keep the bit pattern, otherwise there will be incompatibility.

 6
Author: Garoto de Programa, 2019-08-30 12:56:58