我这里有几段内存碎片整理的程序,希望高手可以告诉我里面用了什么算法,数据结构又如何?
procedure TForm1.Timer1Timer(Sender: TObject);
var ms : TMemoryStatus;
l : longint;
s:string;
begin
ms.dwLength:=sizeof(ms);
GlobalMemoryStatus(ms);
MemBar.Position:=ms.dwAvailPhys shr 19;
s:=Format('%d/%d',[ms.dwAvailPhys, ms.dwTotalPhys]);
LMemInfo.Caption:=s; tr.ReadBinaryData('KERNEL\CPUUsage',l, sizeof(l));
LCPUStat.Caption:=Format('%d %%', [l]);
s:='Memori bebas/Total '+s;
lstrcpy(tnid.szTip, pchar(s));
Shell_NotifyIcon(NIM_Modify, @tnid);
if option.AutoDefrag then
begin
if (option.CPULimit=0) or (l<option.CPULimit) then
begin
if (GetTickCount-lastdefrag)<5000 then exit;
if (membar.position shr 1)<option.MemLimit then
begin
button2click(self);
LastDefrag:=GetTickCount;
end;
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
timer1.Enabled:=false;
Button2.Enabled:=false;
pie.Visible:=true;
pie.MaxValue:=memlevel.position*2;
Defragmem(memlevel.position,idle);
pie.Visible:=false;
Button2.Enabled:=true;
timer1.Enabled:=true;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var ms : TMemoryStatus;
l : longint;
s:string;
begin
ms.dwLength:=sizeof(ms);
GlobalMemoryStatus(ms);
MemBar.Position:=ms.dwAvailPhys shr 19;
s:=Format('%d/%d',[ms.dwAvailPhys, ms.dwTotalPhys]);
LMemInfo.Caption:=s; tr.ReadBinaryData('KERNEL\CPUUsage',l, sizeof(l));
LCPUStat.Caption:=Format('%d %%', [l]);
s:='Memori bebas/Total '+s;
lstrcpy(tnid.szTip, pchar(s));
Shell_NotifyIcon(NIM_Modify, @tnid);
if option.AutoDefrag then
begin
if (option.CPULimit=0) or (l<option.CPULimit) then
begin
if (GetTickCount-lastdefrag)<5000 then exit;
if (membar.position shr 1)<option.MemLimit then
begin
button2click(self);
LastDefrag:=GetTickCount;
end;
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
timer1.Enabled:=false;
Button2.Enabled:=false;
pie.Visible:=true;
pie.MaxValue:=memlevel.position*2;
Defragmem(memlevel.position,idle);
pie.Visible:=false;
Button2.Enabled:=true;
timer1.Enabled:=true;
end;
解决方案 »
- 大哥大姐,兄弟姐妹,帮忙看看,不胜感激。自写组件,设计时能调整大小,运行时比例失调
- 如何用DELPHI制作功能键(快捷键)--在线等(急)!
- 急问:怎么用OleVariant类传递一个图片?
- 50分求书<<delphi7 控件实用程序设计100例>>——电子版
- 操作Oracle执行SQL语句老是出错,高手来看看杂回事?
- 帮帮忙,关序消息的问题!!!
- DBGRID修改或删除出错
- 急!!!在线等待高手!!!在delphi中TEdit除了Text属性可以保存数据,还有什么属性可以保存数据!!!
- >>请问最新版的,网上哪儿可以下载?? <<
- 用菜单与工具栏的比较?
- 正确看待《Delphi高手突破》最后一章的实例 - 很久没提笔了。。。
- dll 中pchar参数问题
protected
procedure minimise(var msg: TMessage); message WM_SYSCOMMAND;
procedure TaskBarHandler(var msg: TMessage); message MyWM_NotifyIcon;
end;
var
Form1: TForm1;
Totalmem : longint; //total memory dalam satuan megabyte
Tr : TRegistry;
tnid : TNotifyIconData;
lastdefrag : longint;
isFirst : boolean;
implementationuses info, option, about;{$R *.DFM}procedure TForm1.Info1Click(Sender: TObject);
begin
Form2.showmodal;
showwindow(Application.Handle, SW_HIDE);
end;procedure TForm1.minimise(var msg: TMessage);
begin
case msg.WParam of
SC_CLOSE : close;
SC_MINIMIZE :
begin
showwindow(Application.Handle, SW_HIDE);
showwindow(Form1.Handle, SW_HIDE);
end;
else
DefWindowProc(Form1.Handle, msg.msg, msg.WParam, msg.LParam);
end;
end;procedure TForm1.Exit1Click(Sender: TObject);
begin
Close;
end;procedure TForm1.FormCreate(Sender: TObject);
var ms : TMemoryStatus;
trg : tregistry;
i : integer;
begin
LastDefrag:=GetTickCount;
tnid.cbSize := sizeof(TNotifyIconData);
tnid.Wnd := Form1.handle;
tnid.uID := $2111;
tnid.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
tnid.uCallbackMessage := MYWM_NOTIFYICON;
tnid.hIcon := Application.Icon.Handle;
Shell_NotifyIcon(NIM_ADD, @tnid);
ms.dwLength:=sizeof(ms);
GlobalMemoryStatus(ms);
TotalMem:=(ms.dwTotalPhys shr 20) + 1;
MemLevel.Max:=Totalmem;
MemBar.Max:=TotalMem*2;
Tr:=Tregistry.create;
tr.RootKey:=HKEY_DYN_DATA;
tr.OpenKey('PerfStats\StatData',false);
pie.Visible:=false;
trg:=tregistry.create;
with trg do
begin
RootKey:=HKEY_CURRENT_USER;
OpenKey(KeyName, true);
i:=ReadInteger('MemToFree');
if (i<MemLevel.Min) or (i>MemLevel.Max) then
begin
i:=MemLevel.Max shr 2;
WriteInteger('MemToFree', i);
end;
MemLevel.Position:=i;
closekey;
free;
end;
LInfo.Caption:=Format(
'Defragmen RAM sebanyak %d Mb', [MemLevel.Position]);
end;procedure TForm1.Timer1Timer(Sender: TObject);
var ms : TMemoryStatus;
l : longint;
s:string;
begin
ms.dwLength:=sizeof(ms);
GlobalMemoryStatus(ms);
MemBar.Position:=ms.dwAvailPhys shr 19;
s:=Format('%d/%d',[ms.dwAvailPhys, ms.dwTotalPhys]);
LMemInfo.Caption:=s; tr.ReadBinaryData('KERNEL\CPUUsage',l, sizeof(l));
LCPUStat.Caption:=Format('%d %%', [l]);
s:='Memori bebas/Total '+s;
lstrcpy(tnid.szTip, pchar(s));
Shell_NotifyIcon(NIM_Modify, @tnid);
if option.AutoDefrag then
begin
if (option.CPULimit=0) or (l<option.CPULimit) then
begin
if (GetTickCount-lastdefrag)<5000 then exit;
if (membar.position shr 1)<option.MemLimit then
begin
button2click(self);
LastDefrag:=GetTickCount;
end;
end;
end;
end;procedure TForm1.MemLevelChange(Sender: TObject);
begin
LInfo.Caption:=Format(
'Defragmen RAM sebanyak %d Mb', [MemLevel.Position]);
end;procedure idle;
begin
Application.processMessages;
Form1.Pie.progress:=Form1.Pie.progress+1;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
timer1.Enabled:=false;
Button2.Enabled:=false;
pie.Visible:=true;
pie.MaxValue:=memlevel.position*2;
Defragmem(memlevel.position,idle);
pie.Visible:=false;
Button2.Enabled:=true;
timer1.Enabled:=true;
end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Shell_NotifyIcon(NIM_DELETE, @tnid);
end;procedure TForm1.Option1Click(Sender: TObject);
begin
Form3.ShowModal;
showwindow(Application.Handle, SW_HIDE);
end;procedure TForm1.About1Click(Sender: TObject);
begin
Form4.showmodal;
showwindow(Application.Handle, SW_HIDE);
end;
procedure Tform1.TaskBarHandler(var msg: TMessage);
begin
case msg.LParamLo of
WM_LBUTTONDOWN :
begin
if not IsWindowVisible(form1.handle)
then showWindow(form1.handle, sw_show);
end;
end;
end;procedure TForm1.FormShow(Sender: TObject);
begin
showwindow(Application.Handle, SW_HIDE);
end;procedure TForm1.FormDestroy(Sender: TObject);
var
trg : tregistry;
begin
trg:=tregistry.create;
with trg do
begin
RootKey:=HKEY_CURRENT_USER;
OpenKey(KeyName, true);
WriteInteger('MemToFree',MemLevel.Position);
closekey;
free;
end;
tr.closeKey;
tr.Free;
end;procedure TForm1.FormPaint(Sender: TObject);
begin
if IsFirst and option.MinOnLoad then
begin
hide;
IsFirst:=false;
end;
end;begin
isFirst:=true;
end.望高手指点,急急急
http://expert.csdn.net/Expert/topic/2385/2385608.xml?temp=.8815271
先谢了