procedure TForm8.FormCreate(Sender: TObject);
var
CDS: TClientDataSet;
Mem: UInt64;
procedure ShowState;
var
GStatus: TMemoryStatusEx;
MMState: TMemoryManagerState;
begin
//Memo1.Lines.Add(' Records ' + CDS.RecordCount.ToString);
GStatus.dwLength := SizeOf(GStatus);
GlobalMemoryStatusEx(GStatus);
GetMemoryManagerState(MMState);
var FastMM: Int64 := 0;
for var i := 0
to High(MMState.SmallBlockTypeStates)
do
Inc(FastMM, MMState.SmallBlockTypeStates[i].UseableBlockSize * MMState.SmallBlockTypeStates[i].AllocatedBlockCount);
Inc(FastMM, MMState.TotalAllocatedMediumBlockSize);
Inc(FastMM, MMState.TotalAllocatedLargeBlockSize);
Memo1.Lines.Add(Format('
Memory %d%% %.2nm %s%.2nm / %.2nm', [
GStatus.dwMemoryLoad, Int64(GStatus.ullTotalVirtual - GStatus.ullAvailVirtual) / 1048576,
IfThen(Mem < GStatus.ullAvailVirtual, '
', '
+'), Int64(Mem - GStatus.ullAvailVirtual) / 1048576,
FastMM / 1048576
]));
Mem := GStatus.ullAvailVirtual;
end;
begin
Mem := 0;
CDS := TClientDataSet.Create(Self);
CDS.FieldDefs.Add('
TEST1', ftString, 500);
CDS.FieldDefs.Add('
TEST2', ftString, 500);
CDS.FieldDefs.Add('
TEST3', ftString, 500);
CDS.CreateDataSet;
for var L := 1
to 99
do
try
Memo1.Lines.Add(L.ToString);
//Memo1.Lines.Add('Add');
for var i := 1
to 9999
do begin
CDS.Append;
CDS.FieldByName('
TEST1').AsString := Random(MaxInt).ToString;
CDS.FieldByName('
TEST2').AsString := Random(MaxInt).ToString;
CDS.FieldByName('
TEST3').AsString := Random(MaxInt).ToString;
CDS.Post;
end;
ShowState;
//Memo1.Lines.Add('Delete');
while CDS.RecordCount > 0
do
CDS.Delete;
ShowState;
except
on E:
Exception do begin
Memo1.Lines.Add(L.ToString + '
: ' + E.
Message);
ShowState;
Break;
end;
end;
end;