Why are 64-bit program files larger than 32 bits?

64-bit compiled files are approx. 20% more than 32-bit executables. I think this is the same for a 64-bit OS and a 32-bit OS. Thank goodness the ratio is not 50%. Is 20% necessary? Do 64-bit programs consume more RAM? Will there be 128 bits more?

Addition: I know a 32-bit word versus a 64-bit word. char 'A' requires 4 bytes in 32-bit mode and 8 bytes in 64-bit memory. Does the executable have tons of constants that are aligned / padded, so are they larger in 64-bit form? IMHO the differences between 64-bit exe and 32-bit exe are the command codes. I think that they do not increase the file size too much, as well as static data and memory addresses. If so, exe contains much more static data than I imagine. It looks like PNG8 vs PNG24 is a bit. Or am I completely wrong.

+4
source share
2 answers

Depending on the ISA (Intel, regardless), the different instructions must be word aligned (which can lead to them taking up more space), and the numerical constants must correspond to the size of the processor word. The binary is filled with int constants: your loops start at zero, etc. In short, the likely cause of the extra space is int padding and word alignment of persistent data.

Depending on how it is compiled, 64-bit code may use more memory. Data structures also want to be word aligned for quick access, and the compiler can choose to place your structures. In addition, depending on the compiler, some constants may resize. (That's why you always see typdefs as uint32: guaranteed size.)

+4
source

One of the reasons for writing a 64-bit program is the possibility of using more RAM. This requires using 8 bytes for the address instead of 4 bytes in a 32-bit program. This may increase the size of the program.

On the other hand, if your program processes data that is essentially 64 bits, it can do this in one command, where the 32-bit program will use two instructions. This would make the program smaller and faster.

char 'A' uses one byte anyway, so that doesn't matter.

+2
source

Source: https://habr.com/ru/post/1391995/


All Articles