为什么一个C / C ++"的Hello World"在千字节? [英] Why is a C/C++ "Hello World" in the kilobytes?

查看:170
本文介绍了为什么一个C / C ++"的Hello World"在千字节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/4838221/why-are-compiled-java-class-files-smaller-than-c-compiled-files\">Why编译较小的Java类文件不是C编译的文件?

只是出于好奇,我刚刚编译你好世界在C,C ++和Java。

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

Java类文件出来仅为423B,我理解,因为运行时不会在二进制包含非常精简。

The Java class file comes out very lean at just 423B which I understand since the runtime isn't included in the binary.

C和C ++的是8.5K和9.2K但是。

The C and C++ ones are 8.5K and 9.2K however.

他们为什么这么比较大的?
我一直认为标准输入输出或者在iostream的动态链接和不添加到可执行文件的大小。

Why are they so relatively big? I always assumed stdio or iostream are linked at dynamically and don't add to the size of the executable.

那么,确实来自所有千字节?
通过查看hexdump都我看到有很多的填充物,我想出于性能的考虑。究竟为什么一个二进制格式组织这样?

So where do all the kilobytes come from? By looking at the hexdump I see that there's a lot of padding, I guess for performance reasons. Why exactly is a binary format organized like that?

PMG的联系是非常有帮助的!

pmg's link is very helpful!

关于填充,我发现它的程序的段的虚拟内存页边界(4096字节),导致它为至少8192字节的对准

Regarding the padding, I found it's the aligning of the program's segments to virtual memory page boundaries (4096 bytes) that causes it to be at least 8192 bytes.

关于Mach-O的二进制​​格式(适用于OS X和iOS)

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

为了获得最佳性能,段应在为PowerPC和x86处理器的虚拟内存页面边界,4096字节对齐。以计算一个段的大小,加起来各部分的大小,则总和四舍五入到下一个虚拟存储器页的边界(4096字节或4千字节)。使用这种算法,一个段的最小尺寸是4千字节,然后它在4千字节的增量大小

For best performance, segments should be aligned on virtual memory page boundaries—4096 bytes for PowerPC and x86 processors. To calculate the size of a segment, add up the size of each section, then round up the sum to the next virtual memory page boundary (4096 bytes, or 4 kilobytes). Using this algorithm, the minimum size of a segment is 4 kilobytes, and thereafter it is sized at 4 kilobyte increments.

引用<一个href=\"http://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/MachORuntime/Reference/reference.html\" rel=\"nofollow\">http://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/MachORuntime/Reference/reference.html

我会做研究,询问下一次前;)

I'll do the research before asking next time ;)

推荐答案

这是你测量什么的问题。如果它是原始可执行文件的大小,这包含了除了code很大的的main()

This is a question of what you're measuring. If it's the raw executable size, this contains a great deal besides the code for main().

由于我们这里使用的共享动态库,大小大量将由看家的数据,如符号表入账,全局偏移表和共享库的描述中对链接 - 在共享库本身不是二进制的code。

As we're using shared dynamic libraries here, a great deal of the size will be accounted for by house-keeping data such as symbol tables, the global offset table and a description of the shared libraries to be linked against - the code of the shared libraries themselves is not in the binary.

iostream库是一个相当大的,也有静态initialisers - 例如初始化 COUT CERR CIN 的对象。这是目标文件必须包含另一回事。

The iostream library is a fairly large, and also has static initialisers - for instance to initialise cout, cerr, and cin objects. This is another thing that object file must contain.

在现实中,大部分额外的大小是不内存驻留在应用程序运行。

In reality, most of the extra size is not memory resident when the application runs.

这篇关于为什么一个C / C ++&QUOT;的Hello World&QUOT;在千字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆