EXE Size

Started by LZM,

LZM

Hi there,
this might not be directly related to BASS, but I am sure I can find an answer, so here it goes. I have been wondering for a while, why the smallest executable linked by MSVC 6.0 is 16K, even though it is clear that smaller executables are possible (see BASS executables, hence the connection). I know that other compilers (e.g. DEVCPP) easily create executables of 4-7K if there isn't much code or data in the program, so what do I have to do to get Visual C++ to do the same? Any takers? And please, let's NOT get into a discussion about the necessity of saving 10kb on today's HDDs. That's not what this question is about.
Thanks, LZM.

Sebastian_Mares

Yes, same thing goes for Visual Basic, too.

(: JOBnik! :)

Hi ;D

You can COMPRESS the .EXE/.DLL files :)

Try: PEtite by Ian Luck:
http://www.un4seen.com/petite

Or UPX:
http://upx.sourceforge.net/

Have fun!

8) JOBnik! 8)

lucraymond

I didnt check many compilers, but I know that borland c++ exe are bigger than MSVC. I also saw a difference in the exe size between MSVC 6 and MSVC.Net. When I compile my VC++ 6 projects under the .NEt Compiler, the exe size are smaller.

There is one thing you shouldnt forget is that many peoples are using software to compress their EXE. Then, when the user launch the .exe, it uncompress itself and launch (transparent operation).

2 Utilities that compress exe come to my mind at the moment:
- UPX is available free (on sourceforce)
- PeCompact is my favorite compressor (shareware)

I have successfully compressed 900k exe to 250k (compression can be better if the exe is big).

if my memory is good, IAN also made is own nasty compressor (I managed to get some info about it in google). Someone managed to made a decompressor at the time but it was of no use against newer version of his compression program.

Xmplay is compressed with the newest non-public version.

Note: I hope I'm not wrong about this information!! :D






lucraymond


I was too slow, someone replied before I posted my message!

:)

Olego

But other than that, is there no strip command in DOS?  ;D

~Olego~

Sebastian_Mares

#6
The problem with PE (portable executable) compressors is the following: if a non-packed program is started multiple times, only the first instance will load DLLs and other files needed into the memory, while all other instances will use the DLLs from the first one. So the DLLs will be shared between the instances.
When compressing the EXE using UPX, ASPack or any other PE compressor, each instance of the tool will load its own DLLs into the user's RAM. All the DLLs will take up a lot of memory space.
Using a lot of memory will cause the computer to access the HDD for swapping and, as HDDs are much slower than RAM, the system will run slower.

LZM

Well, thanks for all the suggestions, but I actually found the best solution myself. For various reasons which I will not get into here, packers are not really the way to go, especially if you can get the same-size results without their overhead. Have a look at
http://freespace.virgin.net/james.brown7/tutorials/minexe.htm and also the msdn arcticle http://msdn.microsoft.com/msdnmag/issues/01/01/hood/default.aspx
The keywords to look out for are "libctiny.lib" and "AggressiveOptimize.h". There might be more up-to-date versions of both files around (I've found another site, but lost the link, supporting up to MSVC7, i.e. .NET). The header file is especially funky and uses an undocumented (cue the X-Files theme) linker-switch. The library file is a custom (stripped down) version of the start-up code included in every exe. I've had some problems with it and it definitely cannot be used for all applications, but then it only makes sense to save 10kb on a small application anyway. The header file, by the way, also merges the data and code sections, so that in the end your exe cannot be decompiled with most decompilers. Nice, free, safeguard against amateur hacking. Have fun coding and c u round.

Atilla

For all Delphi Users who are annoyed by the sizes of the exe files that the compiler produces :

http://bonanzas.rinet.ru

On this URL you can find very helpfull things to reduce the bloat of the Delphi compiler. It's basically the same thing as the links LZM posted offer, but for Delphi. It's a bit of toying around, but it works and size gain is reasonable. Few more KB still matter, even with a 200GB HDD and T1 conncetion :+)