OK.  Didn't want someone sneaking in a school assignment.

Do remember you are working with a 32 bit processor.  So if you are testing
the block for all zeros then test for 32 bit words equal to zero.  Not
bytes.  Then do as suggested in another posting and drop down into
assembler.  In Delphi this is what you'd do.  There are obviously some
boundary issues as the long buffer array needs to start on a longword
boundary.  But if you look at the attached jpg you can see the code
generated by the compiler is already pretty good.

John Dammeyer


unit TestUnit;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TBufferArray = array[0..8192] of Byte;
  PBufferArray = ^TBufferArray;
  TLongBufferArray = array[0..2047] of longword;
  PLongBufferArray = ^TLongBufferArray;
  pLongWord = ^LongWord;

  TForm1 = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
    function test : boolean;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
function TForm1.Test : boolean;
 var
     BufArray : TBufferArray;
     pBufArray : pLongWord; 
     i: Integer;
  begin
    pBufArray := pLongWord(@BufArray);
    Result := False;
    for i := 0 to 2047 do begin
      if  pBufArray^ <> 0 then
                Exit
          else
                inc(pBufArray);
    end;
    Result := True;
end;

end.> Subject: Re: Test memory block
> 
> 
> No, it's a real-life commercial audio player application.  At 
> the end of 
> playing a song, I need to flush the remaining audio buffers 
> from inside 
> a DLL.  I send it a zeroed buffer and it returns the 
> remaining audio in 
> the buffer, and the only way to know it's finished is by testing the 
> returned buffer is all zero.
> 
> Generally the buffer will be between 2k and 8k.
> 
> I'll give your CompareMem idea a go Rob and do some time tests.  Many 
> thanks for that.
> 
> Ross.
> 
> ----- Original Message ----- 
> From: "John Dammeyer" <[EMAIL PROTECTED]>
> To: "'Borland's Delphi Discussion List'" <[email protected]>
> Sent: Friday, November 04, 2005 5:07 AM
> Subject: RE: Test memory block
> 
> 
> This smells remarkably like a school assignment.  Why would 
> you want to 
> do
> this sort of thing many times in real life since testing what touches 
> your
> memory block is probably more efficient?
> 
> John Dammeyer
> 
> _______________________________________________
> 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