Hi everyone,
From the above answer, means if in my threads has create objects, i will face the memory allocations/deallocations bottleneck?
I've a case that I need to create TSQLConnection and TSQLDataSet to query data from 5 tables of the database, each table has more than 10000 records. So I will create 5 threads, each thread accept a tablename as parameter via constructor. Unfortunately, i cannot get more obvious difference of time taken. I've write the following codes:
TMyThread = class(TThread)
private
FTableName: string;
protected
procedure Execute; override;
public
constructor Create(const CreateSuspended: Boolean; const aTableName: string);
reintroduce; overload;
end;
constructor TMyThread.Create(const CreateSuspended: Boolean; const aTableName);
begin
inherited Create(CreateSuspended);
FTableName := aTableName;
FreeOnTerminate := True;
end;
procedure TMyThread.Execute;
var C: TSQLConnection;
D: TDataSet;
begin
C := NewSQLConnection;
try
D := NewSQLDataSet(C, FTableName);
try
D.Open;
while not D.Eof do begin
// Do something
D.Next;
end;
finally
D.Free;
end;
finally
C.Free;
end;
end;
function NewSQLConnection: TSQLConnection;
begin
Result := TSQLConnection.Create(nil);
// Setup TSQLConnection
end;
function NewSQLDataSet(const aConn: TSQLConnection; const aTableName: string):
TSQLDataSet;
begin
Result := TSQLDataSet.Create(aConn);
Result.CommandText := Format('SELECT * FROM %s', [aTableName]);
Result.SQLConnection := aConn;
end;
Is there any advice or recommendation for this case?