Reputation: 1271
My question is regarding types/kinds of application improvements. I would like to improve my thread speed(I can not improve thread's complexity). My question is if instead of integer/longint as parameters to functions I will use byte as type will this change/improve my speed?
Instead of sending arrays, sending pointers to these arrays would this technique improve my speed?
What other tricks can I use to improve my thread's speed(except complexity)
The above code it is a simplification of what I use.
Type TArray = array of integer;
Type PArray = ^TArray;
Procedure TMyThread.ProcessFunction(iNr:integer; vArray:PArray);
begin
vArray^[iNr-2]:=5;
//......
end;
Procedure TMyThread.Execute;
var vArray:TArray;
i,iNr:integer;
begin
Randomize;
While Not Terminated do
begin
iNr:=Random(240);
SetLength(vArray,iNr);
for i:=0 to iNr-1 do
vArray[i]:=i+2
ProcessFunction(iNr,@Array);
end;
end;
Is there any method to improve this?
Upvotes: 2
Views: 517
Reputation: 28839
It's not clear where the alleged performance issue lies since we don't know what ProcessFunction actually does, but one possibility is that performance is killed by the (re)allocation of vArray. If that's the case you can probably speed it up by pre-allocating just one array of 240 that you then pass in along with the actual size you are using on each iteration. And as David Heffernan points out, having an explicit pointer is unnecessary since TArray is already a reference type.
Upvotes: 4