其他语言

本类阅读TOP10

·基于Solaris 开发环境的整体构思
·前两天看到的#pragma用法
·用C写的简单学生成绩管理系统
·射频芯片nRF401天线设计的分析
·入门系列--OpenGL最简单的入门
·简单的CreateRemoteThread例程-初学者必看
·BCB数据库图像保存技术
·GNU中的Makefile
·使用AutoMake轻松生成Makefile
·数据结构

分类导航
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!




相关文章

相关软件




月光软件程序下载编程文档电脑教程网站设计网址导航网络文学游戏天地幽默笑话生活休闲写作范文安妮宝贝
电脑技术编程开发网络专区谈天说地情感世界游戏元素分类游戏热门游戏体育运动手机专区业余爱好影视沙龙
音乐天地数码广场教育园地科学大观古今纵横谈股论金人文艺术医学保健动漫图酷二手专区地方风情各行各业

月光软件站·版权所有