views:

260

answers:

4

I opened up my compiled Hello World Obj-C application in a text editor and, to my surprise, I found about 8 kilobytes of 00 00 00 00 00 00 00 00 ....

Why are these here? Is there a way to clear out these zeroes (which I doubt have too much function)?

Obviously it's not so important in this file, seeing as it's only 16kB to begin with, but I'd like to know anyway.

A: 

Does Objective-C support incremental linking? That would explain why there was a lot of padding space.

Brad Wilson
A: 

Some compilers or linkers want some round number for the file size. You can see that when you add some code, yet the file size does not increase. I guess that's the zeros you are seeing.

OregonGhost
+7  A: 

It's most likely padding between code, data, relocation or other sections of the executable format you use.

Linkers like to pad such sections on a 4k or 8k boundary. This improves loading time for the price of a bit of memory-waste.

For a simple hello world it's significant, but for a large application the extra memory used for the padding is neglible.

Nils Pipenbrinck
A: 

Maybe it's a static variable? I know in many C-like languages, the initial value of a variable that is declared static is embedded in the code emitted by the compiler. At runtime this initial value is mapped to the memory of the process. Maybe you (or some code you're including or linking against) defines an 8 KB zero-initialized array.

Logan