Using std::string leads to large size of executable
Benjamin Kosnik
bkoz@redhat.com
Thu May 15 23:59:00 GMT 2003
>1)
>#include <string>
>int main()
>{
> std::string("a");
> return 0;
>}
>
>lead to ~200k .exe file.
On linux:
%COMP.sh "-O2" string_size.cc
%ll a.out
-rwxrwxr-x 1 bkoz bkoz 12K May 15 18:51 a.out*
Note the difference. Try to use shared libraries, if possible on your
platform. Then, try to eliminate unused debug info (in 3.4, not 3.3 or
3.2).
>2)
>#include <vector>
>int main()
>{
> std::vector <char> a;
> return 0;
>}
>
>lead to ~50k .exe file.
%COMP.sh "-O2" vector_size.cc
%ll a.out
-rwxrwxr-x 1 bkoz bkoz 12K May 15 18:53 a.out*
>I want to use std::string but it too exspensive with such size wasting. I
>have tried next compilers for first example and got:
>mingw-3.2: 200k
>mingw-3.2 with STLport: 89k
>bcc-5.5: 64k
>bcc-5.6: 62k
I have yet to run across smaller binaries than g++ 3.x and libstdc++ on
linux. Cygwin/mingw may have other issues, like the inability to deal
with weak: see if __GXX_WEAK__ is being defined on your platform. That
would explain the size issue.
>So IMHO subj depend on GNU GCC implementation of std::string.
I think it depends on many things, including debugging information,
compilation flags, object file format, etc.
-benjamin
More information about the Libstdc++
mailing list