I'm using Code::Blocks to write my program and when I include <string>
(or <iostream>
) the size of my exe grows. My program is very simple and I need to keep it small <20kb. I'm pretty sure this is happening because of the C++ Standards Committee swapped the old .h versions for many new libraries without the .h. But how would I keep it from adding the ~43kb? Are there settings for Code::Blocks so that it wont add the extra kb or is there another native lib I can use?
views:
200answers:
5If size is your #1 concern (and if you have to keep things < 20KB, then it probably is) then the standard C++ library is probably not the way to go. In fact, any C++ at all (RTTI, exceptions, etc) is probably a bad idea and you would be better off just sticking with straight C.
The header versions without .h aren't different from the others. The .h versions are mostly provided for compability. The additional size would be the string
class, and the size isn't too surprising. If you wan't zero size overhead: Don't use std::string, but char*
.
The next step would be compiler options. Most compilers have the possibility to disable RTTI and to optimize for size. -Os -fno-rtti
would be the right switches for gcc.
Otherwise all standard tricks for size optimization apply:
- Don't have any static data, always calculate
- Don't use virtual functions
- Pack things tight, use bitfields
- Maybe C is a better pick than C++ (This is subject to debate.)
You could try using compiler switches to optimize based on file size. If you don't get anywhere you could try using stlport but I'm not sure if the results will be any better.
Neither <string>
nor <iostream>
are renamed/modified C headers. They are both new to C++. If you want to stick to C libraries, you can use <cstring>
and <cstdio>
(among others), which are the C++ versions of the C headers "string.h"
and "stdio.h"
.
remenber to build your app on - release mode instead of -debug one. that will reduce ur app size a lot.