I have a structure defined like this:
const
MaxSignalRecords=255;
type
TSignalRecord=record
signal1 : integer;
signal2 : integer;
signal3 : integer;
signal4 : integer;
signal5 : integer;
signal6 : integer;
bsignal1 : Boolean;
bsignal2 : Boolean;
bsignal3 : Boolean;
bsignal4 : Boolean;
bsignal5 : Boolean;
bsignal6 : Boolean;
end;
TListSignals = Array[0..MaxSignalRecords-1] of TSignalRecord;
This structure is used to make thousands of calculations in an algorithm like this:
for i:=1 to 900000 do
begin
CleartheList(MyList);
DotheMath(MyList);
DotheChart(MyList);
end;
I am looking for a fast way to initializate the values of my TListSignals
to 0 and false
.
Now I am using this :
procedure ClearListSignals(var ListSignals:TListSignals);
var
i :Integer;
begin
for i := 0 to MaxSignalRecords - 1 do
with ListSignals[i] do
begin
signal1 :=0;
signal2 :=0;
signal3 :=0;
signal4 :=0;
signal5 :=0;
signal6 :=0;
bsignal1 :=false;
bsignal2 :=false;
bsignal3 :=false;
bsignal4 :=false;
bsignal5 :=false;
bsignal6 :=false;
end;
end;
How can I improve the performance of the ClearListSignals
procedure?
you can use the ZeroMemory
procedure located in the Windows
unit.
var
MyList : TListSignals;
begin
ZeroMemory(@Mylist,SizeOf(MyList));
end;
You should use the standard Delphi language function Default()!
const
MaxSignalRecords = 255;
type
TSignalRecord = record
...
bsignal6 : Boolean;
end;
var
X: TSignalRecord
...
X := Default(TSignalRecord);
...
And no hack.. as suggested before..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With