# executable size

This topic is 4247 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Is it normal that using fstream and select windows (lean and mean) function calls push the executable size up to the 130 kB region with size optimizations enabled? I have a few other classes of my own that take up roughly 8 kB (empirical tests showed that), but using an ifstream instance magically adds some 60-80 kB to the program size, even though I'm only using tellg(), seekg() and read(). This seems insane given that the program could be fit into ~5 kB without directly mapping all that unneccessary junk directly into the exe at link time. I'm using VC8, all optimizations geared towards favoring small code size. What's worse, UPX can't directly compress the executable for some reason, so I have to --force it, after which the file is half as large (~62 kB, still way too large), but just plain won't run: "The application failed to initialize properly (0xc0000005)" (displayed twice) The grand flop of all times, to me, is this:
void main(){}


links to 44 kB (again, with size optimizations enabled). Is that normal? I mean, I'd expect some 0.2 - 0.6 kB bytes at most... And yes, before anyone asks - I'm talking about release mode. PS - in this instance I'm talking about a Windows console application.

##### Share on other sites
What compiler? Gcc is known to produce relatively large executables for small programs simply because it has to link the standard library in with the executable if you use it (IIRC). Keep in mind that the amount of junk it adds is constant--once your program starts getting bigger the extra stuff won't be very noticeable.

##### Share on other sites
Are you linking against the DLL CRT ["Multithreaded DLL" in C/C++ Code Generation options] or Static CRT ["Multithreaded" in C/C++ Code Generation options]?

##### Share on other sites
Quote:
 Original post by ShawMishrakAre you linking against the DLL CRT ["Multithreaded DLL" in C/C++ Code Generation options] or Static CRT ["Multithreaded" in C/C++ Code Generation options]?

Okay this is odd.

The default was on MT DLL, which seemed reasonable, but it produced the 130 kB version (which is why I went on a quest to find out what's up). Swithing to MT didn't help much (which sort of makes sense). But now that I switched back to MT DLL the code size cut down to ~10 kB.

Odd, I say. Odd.

bytecoder: the answer is in the OP, and yes I know that. At the moment I'm trying to create a very small sample application and 130 kB seems like people would laugh at me if I gave them that, that's all :)

##### Share on other sites
If it's appropriate for your little demo, consider using assembly language. Probably only a good idea if you're only going to distribute the binary, though.

##### Share on other sites
You are pulling in the entire C runtime with "main()" or "WinMain()". By default, the linker is wired to an entry point that initializes the CRT and then in turn calls either main() or WinMain(). Try making a straight Win32 application (/SUBYSTEM:WINDOWS) and use another entry point (see /ENTRY linker option). Remove explicitely LIBC et al. from your linker options. That solves the size problem for good, but you're out of C runtime support. Say goodbye to fstream...

##### Share on other sites
Don't worry about it - most of that size isn't caused by your code and hence the executable size will no go up linearly with the size of your source.

It's probably all C++ library / init stuff, which will remain constant in size even if your program becomes very large.

Mark

##### Share on other sites
Yeah, I complained about this on GameDev once and got severely told off. The point made to me was that if my program is 100k, an extra 140k of library code seems like a lot, but on a proper size program, say a couple of meg at least, 140k seems pretty trivial.

##### Share on other sites
Quote:
 Original post by irreversiblebytecoder: the answer is in the OP, and yes I know that. At the moment I'm trying to create a very small sample application and 130 kB seems like people would laugh at me if I gave them that, that's all :)

To this I say: Relax. The only people who would even care are programmers. And I am a programmer, and I don't normally care about exe size at all anymore. I cared a lot when I was beginning, though. "If I have a big exe people might think I suck..." was an often occuring thought in the beginning me. The exes were small - I still sucked.