优化c++执行文件效率的方法 (1)自定义程序的入口 (2)合并区段 (3)不用调malloc,free 等函数 (3)不用cout 来输出,cin 来输入 (4)如果调用了很多库函数如memset,stycpy 等等 的话,请导入msvcrt
lib,不然编译器会在程序里面 导入静态库,这样的话程序就会大很多
(5)window 编程不用mfc
减少程序运行内存占用量可以调用 SetProcessWorkingSetSize(GetCurrentProcess(),-1,-1); ----------sample
cpp--------------------- #include #include "sample
h" #include "mydll
h" #include "resource
h" //这下面自定义函数入口 #pragma comment(linker, "/ENTRY:EntryPoint") #pragma comment(linker,"/ALIGN:0x400") //设置区段属性,跟区段在内存起始地址 //这里面要加写入的权限,不然程序就运行不了了 //E 为执行,R 为可读,W 为可写 //更多的说明请参见 msdn #pragma comment(linker,"/SECTION:
text,ERW /ALIGN:0x1000") //下面合并区段, #pragma comment(linker,"/merge:
text") #pragma comment(linker,"/merge:
rdata=
text") //下面导入函数 #pragma comment(lib,"mydll
lib") //下面是函数的入口 //得到 WinMain 里面的几个参数 //HINSTANCE hInstance=GetMod