What are the consequences of programming in 32 bits or 64 bits?

Asked

Viewed 569 times

13

It would only be the memory capacity that is limited to 4 GB in 32 bits?

I need to have specific concerns?

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

3 answers

13


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

The memory consumption of all objects that have pointers will be higher. Although C# has no free pointers (except in context unsafe) there are opaque hands on everything that is a type by reference, since the pointer is the mechanism of obtaining 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 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 because of alignment.

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

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

7

Besides memory, there are other yes:

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

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

6

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 processors (or less).

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 running an application on 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 update DLL’s 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 maintain the bit pattern, otherwise there will be incompatibility.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.