That's very good Melcome, I may use your exact code.  The extra 
0.000000001 millisecond saving at the end is excellent :-)

It appears to be similar to what the FastCode Project's CompareMem does 
in assembler code.

Does the div 4 as apposed to shr 2 use the same number of CPU cycles?

Anyway, I think this thread should die about now...
   TestMemoryBlockThread.Terminate;

Ross.

----- Original Message ----- 
From: "Malcolm Clark" <[EMAIL PROTECTED]>
To: "Borland's Delphi Discussion List" <[email protected]>
Sent: Sunday, November 06, 2005 1:06 AM
Subject: Re: Test memory block


>Just as a matter of interest, I came up with my own fast method working
 >along the lines of John's method but I think this is tidier.

This is starting to resemble a coding competition! Here's my suggestion:

function IsZero(const AddrOfDataToSearch:Pointer; const
LengthInBytes:LongWord) : boolean;
var
  p:pLongWord; //pLongWord defined System unit in D7
  i:LongWord;
begin
  p:=pLongWord(AddrOfDataToSearch);
  result:=false;
  for i:=0 to ((LengthInBytes div 4)-1) do
    if  p^ <> 0 then
      exit
    else
      inc(p);
  case LengthInBytes mod 4 of
    0: result:=true;
    1: if pByte(p)^=0 then result:=true;
    2: if pWord(p)^=0 then result:=true;
    3: if ((pWord(p)^=0) and (PByte(LongWord(p)+2)^=0)) then 
result:=true;
  end;
end;//IsZero

_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to