Note that there are some explanatory texts on larger screens.

plurals
  1. PODelphi 2010: No thread vs threads - TSQLConnection and TSQLDataSet
    primarykey
    data
    text
    <p><a href="https://stackoverflow.com/questions/3632945/delphi-2010-no-thread-vs-threads">My previous question</a></p> <p>From the above answer, means if in my threads has create objects, i will face the memory allocations/deallocations bottleneck?</p> <p>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: </p> <pre><code> 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; </code></pre> <p>Is there any advice or recommendation for this case? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload