Big problem with Small programs

Sean Kelly sean at f4.ca
Tue Jan 23 08:23:58 PST 2007


Walter Bright wrote:
> kris wrote:
>> I have a helloworld.d program. I compile it on both Win32 and on 
>> linux. On linux, the executable is 72KB whereas on Win32 it is 141KB. 
>> Why is this?
>>
>> Turns out that D programs importing comprehensive Win32 D headers will 
>> wind up with executable space occupied for *all* constants and *all* 
>> struct initializers for the darned Win32 decls; where none of them are 
>> actually used.
>>
>> That amounts to ~70KB of junk in the executable -- almost a full 100% 
>> increase in size beyond what it should be.
>>
>> Does OptLink remove this? I've had no success with it. Walter? Can you 
>> help with this?
> 
> Try using enums instead of const variables, they don't take up any space 
> in the object file.

That shaved off maybe 30k.  I think the remaining 40k are mostly static 
struct initializers, all of which are unused in the final app.  As 
optlink is an optimizing linker, shouldn't it discard whatever is unused 
by the application?  Or does that only apply to certain classes of 
information?


Sean



More information about the Digitalmars-d mailing list