Here Are Some Useful Hints for Reduce Your CC ++ Code DramAtically

xiaoxiao2021-03-06  23

Possible Reasons Are:

1. Although the 2 Visual C you are useless is the Same Version, The Service Pack Could Be Different, Thus The Compilers Are Actually Different

2. The discretely

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, Difference is not this 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 DramAtical:

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 setting

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 ee), 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.

5. If you do '' '

6. If you use class inheritance, and you do not 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!

转载请注明原文地址:https://www.9cbs.com/read-48805.html

New Post(0)