stl确实经典~ STL会增大生成的程序包大小,程序包:exe,lib,dll。
实验
1. main函数空时:
int main() { return 0; }
没有引用任何文件。exe大小为:
2. 加入c标准库引用:
#include <stdio.h> #include <stdlib.h> int main() { printf("test"); getchar(); return 0; }
程序包并没有明显变化,大小仍然为28.5k
3. 加入STL的string:
#include <stdio.h> #include <stdlib.h> #include <string> int main() { std::string str = "test\n"; printf(str.data()); getchar(); return 0; }
注意STL中都为模板类,如果没有实例化对象,并不会链接。
加入string后exe大小为:
4. 加入vector
#include <stdio.h> #include <stdlib.h> #include <string> #include <vector> int main() { std::string str = "test\n"; std::vector< int > vect; vect.push_back( 1 ); printf(str.data()); printf("%d\n", vect[0]); getchar(); getchar(); return 0; }
生成的exe包大小:
结论
加入vector后包大小已经翻倍了,好吧 常规的一些功能库 最好DIY吧。。。