views:

406

answers:

3

Recently I have discovered that my release executable (made with msvc++ express 2008) becomes very large. As I examine the executable with a hex viewer I saw that only the first 300k bytes contains useful data the remaining bytes are only zeros - 6 megs of zero bytes.

The debug built exe has 1MB size, but the release is 6.5MB.

Why does MSVC++ express do that useless thing? How can I fix it?

+10  A: 

Did you define large arrays at file-scope in your program? That might be one reason. You can use the dumpbin program to see how much space each section in the exe file takes, that should give you a clue to the "why".

zvrba
Yes! Large arrays. I've never thought that huge arrays do such strange things. I removed all of them and allocate them on the fly. My exe became tiny. But why don't this problem appeared before? Maybe when I reorganized the code placing everything in classes...
Calmarius
In the debug build, there's probably debug code to initialize the array to 0xCD repeated.
MSalters
A: 

Release 6 times larger than Debug - something is probably wrong. Try to create a fresh project and just copy your source code. Compile it and see what you get for the Debug and Release executables.

Eli Bendersky
+2  A: 

Perhaps you are statically linking your .exe in release, but dynamically linking in debug? Check this is the dialog Project Properties.

Another possibility is that in release mode a lot of functions are inlined or you are using a lots of templates.

You can tell the compiler to optimize for size in the dialog Project Properties.

Ismael
Both files are dinamically linked.
Calmarius