{$OVERFLOWCHECKS OFF}
uses
System.StrUtils, Data.DB, Datasnap.DBClient;
procedure TForm8.FormCreate(Sender: TObject);
var
CDS: TClientDataSet;
Mem: UInt64;
procedure ShowState;
var
GStatus: TMemoryStatusEx;
MMState: TMemoryManagerState;
begin
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 / %.1nk records / %.1nk changes', [
GStatus.dwMemoryLoad, Int64(GStatus.ullTotalVirtual - GStatus.ullAvailVirtual) / 1048576,
IfThen(Mem < GStatus.ullAvailVirtual, '
', '
+'), Int64(Mem - GStatus.ullAvailVirtual) / 1048576,
FastMM / 1048576, CDS.RecordCount / 1000, CDS.ChangeCount / 1000
]));
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;
CDS.LogChanges := False;
for var i := 1
to 25
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;
for var i := 1
to 100000
do
try
CDS.RecNo := i
mod {25} CDS.RecordCount + 1;
CDS.Edit;
CDS.FieldByName('
TEST1').AsString := Random(MaxInt).ToString;
CDS.FieldByName('
TEST2').AsString := Random(MaxInt).ToString;
CDS.FieldByName('
TEST3').AsString := Random(MaxInt).ToString;
CDS.Post;
if i
mod 5000 = 0
then
ShowState;
except
on E:
Exception do begin
Memo1.Lines.Add(i.ToString + '
: ' + E.
Message);
ShowState;
Break;
end;
end;
ShowState;
end;