views:

105

answers:

3

The .NET Framework allocates less memory for a Int32 than for a Int64 in 64 bit systems?

+1  A: 

No, they consume the same amount of space, since the smallest addressable space is 64 bits.

Lucas B
@Lucas: they consume the same amount of space in a register. Different amounts in memory.
John Saunders
+1  A: 

Int32 and Int64 should consume the same space on all platforms (meaning an Int32 consumes the same amount as another Int32 on both x86 and x64). On all platforms, Int32 should consume different amount than Int64.

However, both Int32 and Int64 are poor examples, since they are structs. Objects consume significantly different space on x64 vs. x86, because they are basically pointers and pointers on x64 are twice as wide as on x86. This applies to function addresses, jump addresses, vtables, call instructions and so on and so forth. An x64 compiled application, and a IL application JIT code for x64 will be significantly larger than its x86 counterpart. It used to be also that the x86 code generation was more mature and optimized more aggressively simply because the compilers were more mature (this applied to JIT code generation as well) but the compiler caught up and now days the x64 optimizations are on-par, if not better than x86 ones.

Remus Rusanu
Rephrasing your answer: A given struct instance consumes the same memory space in any platform. Different structs consumes different memory space in the same platform. Only objects that consume different space depending on the platform.
Jader Dias
@estourodepilha.com: not always. One example of this is when the struct contains a reference type field or a platform-dependent field, e.g. IntPtr - the same struct declaration will consume more memory on x64.
andras