其他语言

本类阅读TOP10

·基于Solaris 开发环境的整体构思
·使用AutoMake轻松生成Makefile
·BCB数据库图像保存技术
·GNU中的Makefile
·射频芯片nRF401天线设计的分析
·iframe 的自适应高度
·BCB之Socket通信
·软件企业如何实施CMM
·入门系列--OpenGL最简单的入门
·WIN95中日志钩子(JournalRecord Hook)的使用

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
Here are some useful hints for reduce your C/C++ code dramatically

作者:未知 来源:月光软件站 加入时间:2005-5-13 月光软件站

Possible reasons are:
1. Although the 2 Visual C++ you are using are the same version, the service pack could be different, thus the compilers are actually different;

2. The disk sector size could be set differently, although the real sizes are the same, the apparent sizes could differ, you can find this out by checking the real sizes of the 2 executables;

3. The 2 executable files could be that one is release version, which is smaller, and the other is debug version, which is bigger. If you use MFC or ATL, the difference will be very big, but if you use pure API, the difference is not that much;

4. The version of C run time (CRT) library could be different on the 2 machines, and that results in different size of code linked to the executable;

Here are some useful hints for reduce your C/C++ code dramatically:

1. Use the magical NOWIN98 switch (if your application is not to be compiled on Win98/95 platforms). Simply put the following line at the beginning of your .cpp file or .h file:
#pragma comment(linker, "/OPT:NOWIN98");

2. Use the minimize size optimization in the project settings;

3. Use MSVCRT.dll instead of the statically linked CRT library. In Visual C++, in the project settings, go to link section, in general category, in "object/library modules", delete the unnecessary .lib files, for example the odbc.lib (if you don't want to use odbc), and then put msvcrt.lib;

4. If you don't want to use the Structured Exception Handling in C++, you need to turn it off in project settings;

5. If you don't need the Run Time Type Information (RTTI) in C++, you need to turn it off in project settins;

6. If you use class inheritance, and you don't want the overhead of virutal function dispatch table (vtable), you can use the magicall __declspec(novtable) modifier. ATL uses this a lot;

7. If you are writing a tiny dll for fast downloading, then you need to careful of the function naming, make the function names as short as possible and then use the alias in full-sized name in the C++ header file, because the ASCII decription of the function names and signatures will occupy a significant amount of space;

8. Most of all, do not allow the compiler to generate debug information.

Test these tricks with a simple "hello world" Win32 console program, the original size without optimization is 40KB, after all possible optimization tricks, the size is 3KB!




相关文章

相关软件