Why is C / C ++ "Hello World" in kilobytes?

Possible duplicate:
Why are compiled Java class files less than C compiled files?

Just out of curiosity, I just compiled Hello Worlds in C, C ++, and Java.

The Java class file only looks very meager on the 423B, which I understand since the runtime is not included in the binary.

C and C ++ have a value of 8.5K and 9.2K.

Why are they so big? I always assumed that stdio or iostream are linked dynamically and do not add to the size of the executable.

So where do all kilobytes come from? Looking at hexdump, I see that there are many add-ons, I think, for performance reasons. Why is the binary format exactly this way?


Link

pmg is very useful!

Regarding indentation, I found that aligning program segments to the borders of virtual memory pages (4096 bytes) leads to the fact that it is at least 8192 bytes.

Regarding binary mach-o format (for OS X and iOS)

For best performance, segments should be aligned at the borders of virtual memory pages - 4096 bytes for PowerPC and x86 processors. To calculate the size of a segment, add the size of each section, then round the amount to the next border of the virtual memory page (4096 bytes or 4 kilobytes). Using this algorithm, the minimum segment size is 4 kilobytes, and then its size is 4 kilobytes.

quoting http://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/MachORuntime/Reference/reference.html

I will do research before asking next time;)

+2
source share
4 answers

This is a question of what you are measuring. If this is the raw size of the executable, it contains a lot, except for the code for main() .

Since we use shared dynamic libraries here, the large size will be taken into account by household data, such as symbol tables, a global offset table and a description of shared libraries that must be linked against - the code of the shared libraries themselves is not in binary format.

The iostream library is quite large and also has static initializers - for example, to initialize the cout , cerr and cin objects. This is another thing that an object file should contain.

In fact, most of the extra size is not resident when the application is running.

+4
source

C and C ++ is a complete standalone program. Java is just the core code, and another program is required to run it.

The small world of hello should use a bash script (which also requires a different program to run)

 echo Hello World 

17 bytes in total with a new line.

+2
source

because stdlib is included. try using -nostdlib

+1
source

One factor

 #include <iostream> 

which leads to the fact that most of the standard library is associated with your program. However, no need to worry. This is just the initial invoice, it does not increase with the complexity of the program or the length of the code. In any case, try using UPX .

+1
source

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


All Articles