big code bloat because of STL

hi,
I was making a program which used the STL std::list container,
and it suddenly bloated my program from ~300k to 1.3m (debug),and
the release version from <100k to 400k. I know the previous sizes
since I switched to STL mid-project, and was using my own list class
before :P Is this exe size normal? Thanks
closed account (Dy7SLyTq)
are you doing using namespace std or using std::list
300k to 1.3m of what?
Executable file size? Object instructions? Source lines? ???

If you're referring to executable file size, that includes synbols for debugging. That's not a good measure of the amount of code executed by your program.
DTSCode wrote:
are you doing using namespace std or using std::list


This doesn't matter. It's just a stylistic thing.

AbstractionAnon wrote:
If you're referring to executable file size, that includes synbols for debugging


The Release build usually doesn't. Though I agree measuring the Debug executable size is totally worthless.

zsteve wrote:
I know the previous sizes
since I switched to STL mid-project, and was using my own list class
before :P Is this exe size normal?


No it's not normal. And frankly, I'm skeptical of your results.

My advice would be to do a small scale test, and if possible, post it here so we can replicate your results and give you a second opinion.
Hi,
I'll just post the full source right now, It's not much code,
the program reports itself to be - 1231 lines of code, most of it is file operation etc.
link:http://0x4c.phatcode.net/files/misc/linecountpp.7z
Just <include> iostream adds 500KB in release mode, executable stripped, to any program using MinGW compiler, even if you don't use anything from it.
1
2
3
4
#include <iostream>
int main () {
return 0;
}


Run the exactly same code without iostream gets you some 8-9KB exe.

Well, yes, but that's like saying that if I put a pea inside a matchbox, it makes the whole thing much bigger. It only seems like it's a lot bigger because the thing you're starting with is tiny!

@modoran
I get 5080 bytes with gcc/linux, 4800 bytes with clang/linux, 3200 bytes with xlc/aix, and 7532 bytes with cc/solaris.
modoran wrote:
Just <include> iostream adds 500KB in release mode, executable stripped, to any program using MinGW compiler, even if you don't use anything from it.


That's insane. I wouldn't expect any increase in file size, but having tested the same thing in MSVS it does appear to happen. That is utterly baffling to me. (Until I thought about it some more, read further down in my post)

MSVS doesn't have near the same numbers though. With full optimizations on I get the following in VS2012 Express:

- Empty main() with no includes, dynamic link to runtime: 7K
- Empty main(), including iostream, dynamic link: 11K
- Empty main(), no includes, static link: 56K
- Empty main(), including iostream, static link: 79K

My only thought is that MinGW's default "Release" settings are poor and you should go over optimization settings manually to make sure they're switched on. Either that or its optimizer sucks, which I highly doubt.


At first I didn't expect adding an unused header to increase filesize at all... then I remembered <iostream> has global variables (cout/cin), which means there is additional code for ctors/dtors being run... and they can't be optimized out due to possible side effects. So therefore it makes sense.

The same test... but including <list> (which has no global objects to my knowledge -- and is what the OP was asking about):

- Empty main(), no includes, dynamic link: 7K
- Empty main(), include list, dynamic link: 7K
- no includes, static link: 56K
- include list, static: 56K


So that makes perfect sense.

The next thing was testing the actual std::list class, as this is what OP was actually asking about. This is trickier because I imagine the compiler might optimize out the class usage entirely... but here's some basic usage:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <list>

int main()
{
    std::list<int>  foo;
    foo.push_back(4);
    foo.push_back(8);
    foo.push_back(12);

    auto i = foo.begin();
    ++i;
    foo.erase(i);

    int sum = 0;
    for(auto& i : foo)
        sum += i;

    return sum;
}


- Dynamic link = 8K
- Static link = 79K


So I would hardly call that bloated.


zsteve wrote:
I'll just post the full source right now, It's not much code,
the program reports itself to be - 1231 lines of code, most of it is file operation etc.


I'll check this out now and see if I can figure out what's up.

For reference, what compiler are you using?

EDIT: err... the link 404s for me. I can't download it.
Last edited on
Cubbi wrote:
@modoran
I get 5080 bytes with gcc/linux, 4800 bytes with clang/linux, 3200 bytes with xlc/aix, and 7532 bytes with cc/solaris.


When I said MinGW I was reffering to windows, default settings, release mode.
@disch: sorry, the link was case sensitive.
http://0x4c.phatcode.net/files/misc/LineCountPP.7z
Topic archived. No new replies allowed.