Znn3bq.jpeg
²é¿´: 477  |  »Ø¸´: 0

zyj8119

ľ³æ (ÖøÃûдÊÖ)

[½»Á÷] ¡¾×ªÌû¡¿delphiÖÐÈçºÎ¼ì²âÄÚ´æÍ¸Â¶(null)

ÊÔÊÔżÕâ¸öÄÚ´æÓ¦Óà ¼à¶½ Æ÷
Ó÷¨·Ç³£¼òÂÔ £¬ÔÚÄãµÄproject sourceÀï°Ñ
ÀûÓà Õâ¸öµ¥ÔªµÄÄǾä·Åµ½×îǰ£¬Èç
...
CODE:
uses
MemoryManager in '...pas',
Forms,
Main in 'Main.pas' {frmMain},
...
ÐÞÕý ×ÔDelphi Developer's Handbook¡­¡­
´úÂëÈçÏ¡­¡­
unit MemoryManager;
interface
var
GetMemCount: Integer = 0;
FreeMemCount: Integer = 0;
ReallocMemCount: Integer = 0;
var
mmPopupMsgDlg: Boolean = True;
mmSaveToLogFile: Boolean = True;
mmErrLogFile: string = '';
¡¡
procedure SnapToFile(Filename: string);
implementation
uses
Windows, SysUtils, TypInfo;
const
MaxCount = High(Word);
var
OldMemMgr: TMemoryManager;
ObjList: array[0..MaxCount] of Pointer;
FreeInList: Integer = 0;
procedure AddToList(P: Pointer);
begin
if FreeInList > High(ObjList) then
begin
MessageBox(0, 'ÄÚ´æ¹ÜÀí¼à¶½ Æ÷Ö¸ÕëÁбíÒç³ö£¬ÇëÔö´óÁбíÏîÊý£¡', 'ÄÚ´æ¹ÜÀí¼à¶½ Æ÷', mb_ok);
Exit;
end;
ObjList[FreeInList] := P;
Inc(FreeInList);
end;
procedure RemoveFromList(P: Pointer);
var
I: Integer;
begin
for I := 0 to FreeInList - 1 do
if ObjList[I] = P then
begin
Dec(FreeInList);
Move(ObjList[I + 1], ObjList[I], (FreeInList - I) * SizeOf(Pointer));
Exit;
end;
end;
procedure SnapToFile(Filename: string);
var
OutFile: TextFile;
I, CurrFree, BlockSize: Integer;
HeapStatus: THeapStatus;
Item: TObject;
ptd: PTypeData;
ppi: PPropInfo;
begin
AssignFile(OutFile, Filename);
try
if FileExists(Filename) then
Append(OutFile)
else
Rewrite(OutFile);
CurrFree := FreeInList;
HeapStatus := GetHeapStatus; { ¾Ö²¿¶Ñ״̬ }
with HeapStatus do
begin
writeln(OutFile, '--');
writeln(OutFile, DateTimeToStr(Now));
writeln(OutFile);
write(OutFile, '¿ÉÓõØÖ·¿Õ¼ä : ');
write(OutFile, TotalAddrSpace div 1024);
writeln(OutFile, ' ǧ×Ö½Ú');
write(OutFile, 'δÌá½»²¿·Ö : ');
write(OutFile, TotalUncommitted div 1024);
writeln(OutFile, ' ǧ×Ö½Ú');
write(OutFile, 'ÒÑÌá½»²¿·Ö : ');
write(OutFile, TotalCommitted div 1024);
writeln(OutFile, ' ǧ×Ö½Ú');
write(OutFile, '¿ÕÏв¿·Ö : ');
write(OutFile, TotalFree div 1024);
writeln(OutFile, ' ǧ×Ö½Ú');
write(OutFile, 'ÒÑ·ÖÅ䲿·Ö : ');
write(OutFile, TotalAllocated div 1024);
writeln(OutFile, ' ǧ×Ö½Ú');
write(OutFile, 'µØÖ·¿Õ¼äÔØÈë : ');
write(OutFile, TotalAllocated div (TotalAddrSpace div 100));
writeln(OutFile, '%');
write(OutFile, 'Õû¸ö С¿ÕÏÐÄÚ´æ¿é : ');
write(OutFile, FreeSmall div 1024);
writeln(OutFile, ' ǧ×Ö½Ú');
write(OutFile, 'Õû¸ö ´ó¿ÕÏÐÄÚ´æ¿é : ');
write(OutFile, FreeBig div 1024);
writeln(OutFile, ' ǧ×Ö½Ú');
write(OutFile, 'ÆäËüδÓÃÄÚ´æ¿é : ');
write(OutFile, Unused div 1024);
writeln(OutFile, ' ǧ×Ö½Ú');
write(OutFile, 'ÄÚ´æ¹ÜÀíÆ÷ºÄËð : ');
write(OutFile, Overhead div 1024);
writeln(OutFile, ' ǧ×Ö½Ú');
end;
writeln(OutFile);
write(OutFile, 'ÄÚ´æ¶ÔÏóÊýÄ¿ : ');
writeln(OutFile, CurrFree);
for I := 0 to CurrFree - 1 do
begin
write(OutFile, I: 4);
write(OutFile, ') ');
write(OutFile, IntToHex(Cardinal(ObjList[I]), 16));
write(OutFile, ' - ');
BlockSize := PDWORD(DWORD(ObjList[I]) - 4)^;
write(OutFile, BlockSize: 4);
write(OutFile, '($' + IntToHex(BlockSize, 4) + ')×Ö½Ú');
write(OutFile, ' - ');
try
Item := TObject(ObjList[I]);
// code not reliable
{ write (OutFile, Item.ClassName);
write (OutFile, ' (');
write (OutFile, IntToStr (Item.InstanceSize));
write (OutFile, ' bytes)');}
// type info technique

if PTypeInfo(Item.ClassInfo).Kind <> tkClass then
write(OutFile, '²»ÊǶÔÏó')
else
begin
ptd := GetTypeData(PTypeInfo(Item.ClassInfo));
// name, Èç¹ûÊÇTComponent
ppi := GetPropInfo(PTypeInfo(Item.ClassInfo), 'Name');
if ppi <> nil then
begin
write(OutFile, GetStrProp(Item, ppi));
write(OutFile, ' : ');
end
else
write(OutFile, '(δÃüÃû): ');
write(OutFile, PTypeInfo(Item.ClassInfo).Name);
write(OutFile, ' (');
write(OutFile, ptd.ClassType.InstanceSize);
write(OutFile, ' ×Ö½Ú) - In ');
write(OutFile, ptd.UnitName);
write(OutFile, '.pas');
end
except
on Exception do
write(OutFile, '²»ÊǶÔÏó');
end;
writeln(OutFile);
end;
finally
CloseFile(OutFile);
end;
end;
function NewGetMem(Size: Integer): Pointer;
begin
Inc(GetMemCount);
Result := OldMemMgr.GetMem(Size);
AddToList(Result);
end;
function NewFreeMem(P: Pointer): Integer;
begin
Inc(FreeMemCount);
Result := OldMemMgr.FreeMem(P);
RemoveFromList(P);
end;
function NewReallocMem(P: Pointer; Size: Integer): Pointer; begin
Inc(ReallocMemCount);
Result := OldMemMgr.ReallocMem(P, Size);
RemoveFromList(P);
AddToList(Result);
end;
const
NewMemMgr: TMemoryManager = (
GetMem: NewGetMem;
FreeMem: NewFreeMem;
ReallocMem: NewReallocMem);
initialization
GetMemoryManager(OldMemMgr);
SetMemoryManager(NewMemMgr);
finalization
SetMemoryManager(OldMemMgr);
if (GetMemCount - FreeMemCount) <> 0 then
begin
if mmPopupMsgDlg then
MessageBox(0, PChar(Format('³öÏÖ%d´¦ÄÚ´æÂ©¶´: ',
[GetMemCount - FreeMemCount])), 'ÄÚ´æ¹ÜÀí¼à¶½ Æ÷', mb_ok);
if mmErrLogFile = '' then
mmErrLogFile := ExtractFileDir(ParamStr(0)) + '.Log';
if mmSaveToLogFile then
SnapToFile(mmErrLogFile);
end;
end.

»Ø¸´´ËÂ¥

» ²ÂÄãϲ»¶

ºÃºÃѧϰ£¬ÌìÌìÏòÉÏ¡£
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû
Ïà¹Ø°æ¿éÌø×ª ÎÒÒª¶©ÔÄÂ¥Ö÷ zyj8119 µÄÖ÷Ìâ¸üÐÂ
×î¾ßÈËÆøÈÈÌûÍÆ¼ö [²é¿´È«²¿] ×÷Õß »Ø/¿´ ×îºó·¢±í
[¿¼ÑÐ] ²ÄÁϵ÷¼Á +14 Ò»ÑùYWY 2026-04-06 14/700 2026-04-08 23:00 by Öí»á·É
[¿¼ÑÐ] Ò»Ö¾Ô¸211£¬»¯Ñ§Ñ§Ë¶£¬310·Ö£¬±¾¿ÆÖصãË«·Ç£¬Çóµ÷¼Á +15 ŬÁ¦·Ü¶·112 2026-04-06 17/850 2026-04-08 22:27 by ¿­¿­Òª±ä˧
[¿¼ÑÐ] 285Çóµ÷¼Á +12 AZMK 2026-04-05 18/900 2026-04-08 20:43 by ÄæË®³Ë·ç
[¿¼ÑÐ] 277Çóµ÷¼Á +4 ¿¼Ñе÷¼Álxh 2026-04-06 6/300 2026-04-08 10:40 by ÄæË®³Ë·ç
[¿¼ÑÐ] 283·ÖÇóµ÷¼Á +14 ÊÔÊÔ¿´ß 2026-04-04 14/700 2026-04-08 07:03 by lijunpoly
[¿¼ÑÐ] ²ÄÁϵ÷¼Á +13 ºº123456 2026-04-07 14/700 2026-04-07 22:53 by À´¿´Á÷ÐÇÓê10
[¿¼ÑÐ] ²ÄÁϹ¤³Ì302·ÖÇóµ÷¼Á +13 zyxÉϰ¶£¡ 2026-04-04 13/650 2026-04-07 11:14 by Ê«Óë×ÔÓÉ
[¿¼ÑÐ] 334·Ö¿ØÖƹ¤³ÌÇóµ÷¼Á +4 ½ªÉÐÕæsadasd 2026-04-03 4/200 2026-04-07 09:26 by À¶ÔÆË¼Óê
[¿¼ÑÐ] ²ÄÁÏÓ뻯¹¤371Çóµ÷¼Á +14 ÅãÁÕ¿´º£ 2026-04-04 15/750 2026-04-06 06:59 by houyaoxu
[¿¼ÑÐ] ¿¼Ñе÷¼Á +5 ÃÀÀöµÄyouth_ 2026-04-04 6/300 2026-04-06 06:57 by houyaoxu
[¿¼ÑÐ] 306·Ö²ÄÁÏÓ뻯¹¤Çóµ÷¼Á +7 Àè°ÉÀ²À²ÄãºÜÓÐà 2026-04-03 7/350 2026-04-05 17:18 by Hdyxbekcb
[¿¼ÑÐ] 313Çóµ÷¼Á +5 º£ÈÕº£ÈÕ 2026-04-04 7/350 2026-04-05 13:58 by imissbao
[¿¼ÑÐ] 290Çóµ÷¼Á +7 luoziheng 2026-04-04 7/350 2026-04-04 23:17 by lqwchd
[¿¼ÑÐ] µ÷¼Á +9 19945159693 2026-04-03 10/500 2026-04-04 20:16 by dongzh2009
[¿¼ÑÐ] 368Çóµ÷¼Á +5 ½ñ»ªÏ° 2026-04-03 7/350 2026-04-04 18:47 by imissbao
[¿¼ÑÐ] 22408Çóµ÷¼Á 354·Ö ¿É¿çרҵ +3 hannnnnnn 2026-04-04 3/150 2026-04-04 14:35 by ÍÁľ˶ʿÕÐÉú
[¿¼ÑÐ] 335Çóµ÷¼Á +7 ÉòÇåÁ§ 2026-04-03 7/350 2026-04-03 18:55 by lijunpoly
[¿¼ÑÐ] ¿¼Ñе÷¼Á +3 Draa 2026-04-03 3/150 2026-04-03 17:37 by hgwz7468
[¿¼ÑÐ] 338Çóµ÷¼Á +7 êɹ¦? 2026-04-03 7/350 2026-04-03 16:46 by wxiongid
[¿¼ÑÐ] ÍÁľˮÀû328·ÖÇóµ÷¼Á +6 ¼²·çÖª¾¢²Ý666 2026-04-02 6/300 2026-04-03 11:38 by znian
ÐÅÏ¢Ìáʾ
ÇëÌî´¦ÀíÒâ¼û