You could Sort the Vector in a Descendent Order. If you do that, the first
element of the vector would be the biggest. If this element is different of
zero, you will leave the lace in the first comparison. If the first element
of the vector is 0, you won't have to go through all the vector's elements,
because the biggest element is 0. Doing that, you will only check the first
element of the vector.
Try sorting it with QuickSort, but you will have to modify it to Sort in the
descendent order.

I hope I helped ya !

Ciao !


----- Original Message ----- 
From: "Ross Levis" <[EMAIL PROTECTED]>
To: "Delphi Discussion List" <[email protected]>
Sent: Thursday, November 03, 2005 8:54 AM
Subject: Test memory block


> I'm looking for the fastest way to test if a block of memory is all
> zeros or not.  This needs to be as fast as possible since it is being
> tested many times a second.
>
> The memory block can be any length.  Assuming Buffer is a pointer to a
> block of memory, and BufferSize is the length of the block, I'm
> currently doing it like this.
>
> type
>   TBufferArray = array[0..0] of Byte;
>   PBufferArray = ^TBufferArray;
> ....
>   var
>      BufArray: BufferArray;
>      i: Integer;
>   begin
>     BufArray := Buffer;
>     Result := False;
>     for i := 0 to BufferSize-1 do
>       if Buffer[i] <> 0 then Exit;
>     Result := True;
>
>
> This is reasonably quick but I'm wondering if there is a faster way that
> does not need to increment an integer many times.
>
> Thanks,
> Ross.
>
> _______________________________________________
> Delphi mailing list -> [email protected]
> http://www.elists.org/mailman/listinfo/delphi

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

Reply via email to