----- Original Message ----- 
From: "John Dammeyer" <[EMAIL PROTECTED]>
To: "'Borland's Delphi Discussion List'" <[email protected]>
Sent: Saturday, November 05, 2005 3:59 PM
Subject: RE: Test memory block


Hi Ross,

You're making a lot of assumptions on how the compiler is going to do
things.  Although this is usually more applicable to embedded micro's I
can't stress enough if speed or size is a concern you must look at how 
the
compiler does things.  Your method does 'appear' tidier but has some 
speed
penalties. The biggest one is

Buffer32[i]

You may recall I took specific pains to declare and use pointers here 
since
ultimately that's what the compiler does when it dereferences 
Buffer32[i].
Since 'i' is a loop variable Delphi complains if you assign to it so a
peephole optimizer may just discover the code sequence and substitute
pointer arithmetic but can you be sure.

Since the goal is speed, it's not a good idea to include an extra 
addition
and multiplication

@Buffer32 + i * sizeof(longword) which is what Buffer32[i] is.

The second part of your test looks at the last 3 bytes of a longword.
First,  I believe it checks up to the first
3 bytes of the buffer which you've already looked at.  Minor glitch. 
Unless
you're expecting the array to sit on a BYTE boundry rather than long 
word.
Again,  checking the compiler you'll see that it always declares data on 
at
least a 16 bit boundry.  It's not efficient for the compiler to use odd
addresses.  That showed up in the original PASCAL definition with the 
word
Packed.

John Dammeyer




Wireless CAN with the CANRF module now available.
http://www.autoartisans.com/products
Automation Artisans Inc.
Ph. 1 250 544 4950


> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Ross Levis
> Sent: Friday, November 04, 2005 3:10 PM
> To: Borland's Delphi Discussion List
> 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.
>
> type
>   TBuffer32 = array[0..0] of LongWord;
>   PBuffer32 = ^TBuffer32;
>
>   TBuffer8 = array[0..0] of Byte;
>   PBuffer8 = ^TBuffer8;
>
> function IsZero(Buffer32: Pointer; BufferSize: Integer): Boolean;
> var
>   Size32: Integer;
>   Buffer8: PBuffer8;
>   Buffer32: PBuffer32;
>   i: Integer;
> begin
>   Result := False;
>   Buffer32 := Buffer;
>   Size32 := BufferSize shr 2;
>   for i := 0 to Size32-1 do
>     if Buffer32[i] <> 0 then  // test 4 bytes at a time
>       Exit;
>   Buffer8 := Buffer;
>   for i := 0 to BufferSize - (Size32 shl 2) -1 do
>     if Buffer8[i] <> 0 then  // test remaining 1,2, or 3 bytes
>       Exit;
>   Result := True;
> end;
>
>
> Regards,
> 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

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

Reply via email to