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

9

Would it be only the memory capacity that is 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 #.

    
asked by anonymous 26.04.2017 / 16:01

3 answers

9

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

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

The consumption of the object itself increases even if it does not have members by reference. Every object in heap needs two CPU words , one of which 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 be the same size as the previous word up because questions of alignment .

So it's obvious that with the pointer, this header that every object has will be larger.

In addition, the type IntPtr has its size changed since it is pointer.

If I remember anything else I post.

    
26.04.2017 / 16:09
4

More information to complement Rodrigo's responses and bigown.

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

Since we have not seen this kind of machine in 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 in a museum piece. But I think it's worth mentioning, anyway.

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

    
26.04.2017 / 17:12
3

In addition to memory, there are other yes:

  • DLLs are loaded into applications with equivalent bits. If you try to load a 32-bit DLL in a 64-bit application, the BadImageFormatException
  • Specific platform types, IntPtr for example, have different sizes.
  • Interprocess communication can have problems when done between 32-bit and 64-bit processes. For example, ReadProcessMemory may fail when a 32-bit process tries to read from a 64-bit process.
  • There is also the status of Registry Reflection , explained on MSDN.

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

    
26.04.2017 / 16:21