unit SCFastMemory;
interface
uses
SysUtils, Windows;
implementation
var
InProc: Boolean;
TimerID: Integer;
procedure SaveMemory;
begin
if Win32Platform = VER_PLATFORM_WIN32_NT then
begin //整理内存
SetProcessWorkingSetSize(GetCurrentProcess, $FFFFFFFF, $FFFFFFFF);
end;
end;
//定时器要执行的回调函数
procedure HearBeatProc(Wnd: HWnd; Msg, EVEnt, dwTime: Integer); stdcall;
begin
if (InProc = False) then
begin
InProc := True;
try
SaveMemory;
finally
InProc := False;
end;
end;
end;
initialization
后果很严重
SetTimer(0, 0, 3000, @HearBeatProc); //创建一个定时器
finalization
KillTimer(0, TimerID);
end.
保存为一个PAS,放到工程目录内,然后在主程序内引用即可。哈哈。没有使用前,程序内存占11M,使用后程序占用内存不超过500K。
本文介绍了一种通过PAS文件实现的内存优化方法,能在不影响程序运行的情况下显著降低内存占用,从11M减少到500K。该方法利用定时器定期调用整理内存的函数,适用于Win32平台。

6348

被折叠的 条评论
为什么被折叠?



