#include <string> adding ~ 43KB to my exe
I am using Code :: Blocks to write my program and when I include <string>
(or <iostream>
) my exe grows in size. My program is very simple and I need to keep it small <20kb. I'm sure this is due to the C ++ Standards Committee replacing older versions of .h for many newer libraries without .h. But how can I keep it from adding ~ 43kb? Is there a setting for Code :: Blocks so that it doesn't add extra kb or is there some other native lib I can use?
a source to share
If size is your # 1 problem (and if you need to store things <20KB, then it probably is), then the C ++ standard library is probably not the right fit. In fact, any C ++ in general (RTTI, exceptions, etc.) is probably a bad idea and you'd be better off just sticking to straight C.
a source to share
Versions of headers without .h are no different from others. The .h versions are mainly provided for compilation. The extra size would be a class string
, and the size isn't too surprising. If you haven't typed in size zero: don't use std :: string, but char*
.
The next step is the compiler options. Most compilers have the ability to disable RTTI and optimize for size. -Os -fno-rtti
would be the correct switch for gcc.
Otherwise, all standard sizing tricks apply:
- You have no static data, always count
- Don't use virtual functions
- Pack tightly, use bit fields
- Perhaps C is a better choice than C ++ (this might be a topic for discussion.)
a source to share