Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why 64bit program files are bigger than 32bits? [closed]

64bit compiled files are approx. 20% bigger than 32bit executables. I think it's same for 64bit OS vs 32bit OS. Thanks god the ratio is not 50%. Is 20% really necessary? Do 64 bit programs consume more RAM either? Will 128bits be much bigger?

Addition: I know 32bit word vs 64bit word. The char 'A' requires 4 bytes in 32 bit mode and 8 bytes in 64bit in memory. Does an executable contain tons of constants which aligned/padded so it's bigger in 64bit form? IMHO the differences between 64bit exe & 32bit exe are instruction codes -I think they don't inflate the file size too much- and static data & memory addresses. If so, an exe contains much more static data than I imagine. It looks like PNG8 vs PNG24 a bit. Or I'm totally wrong.

like image 810
Nime Cloud Avatar asked Jan 20 '12 08:01

Nime Cloud


Video Answer


2 Answers

Depending on the ISA (Intel, ARM, whatever), various instructions need to be word-aligned (which may cause them to take more space), and numerical constants need to match the processor's word size. Binary code is full of int constants: your loops start at zero, etc. In short, the likely cause of the extra space is int padding and word alignment of constant data.

Depending on how it's compiled, 64-bit code may well use more memory. Data structures also want to be word-aligned for fast access, and the compiler may choose to pad your structs. Also, depending on the compiler, some int constants may change size. (That's why you always see typdefs like uint32: guaranteed size.)

Last but not least, pointers take twice the memory.

like image 81
Paul Cantrell Avatar answered Nov 05 '22 23:11

Paul Cantrell


One reason for writing a 64-bit program is to be able to use more RAM. This requires using 8 bytes for an address instead of 4 bytes in a 32-bit program. That might increase the program size.

On the other hand, if your program handles data that is intrinsically 64 bits, it can do that in a single instruction where a 32-bit program would use two instructions. This would make the program smaller and faster.

The char 'A' uses a single byte in either case, so that doesn't matter.

like image 34
Bo Persson Avatar answered Nov 06 '22 00:11

Bo Persson