#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?

+2


a source to share


5 answers


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.



+10


a source


Neither <string>

nor <iostream>

renamed / changed C headers. They are both new to C ++. If you want to stick with the C libraries, you can use <cstring>

and <cstdio>

(among others), which are the C ++ versions of the C "string.h"

and "stdio.h"

.



+6


a source


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.)
0


a source


You can try using compilers to optimize based on file size. If you don't get anywhere you can try using stlport , but I'm not sure if the results will be better.

0


a source


Remember to build your application in release mode instead of -debug. This will greatly reduce the size of your application.

0


a source







All Articles