[fpc-pascal] Array clearing

Ryan Joseph ryan at thealchemistguild.com
Tue Apr 4 13:55:03 CEST 2017


> On Apr 4, 2017, at 4:58 PM, Howard Page-Clark via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
> 
> You can always use FillChar and its kin on specific 'nested' arrays like this
> 
> type
>  TIntArray = array of Integer;
>  TIntIntArray = array of TIntArray;
>  TIntIntIntArray = array of TIntIntArray;
> 
>  procedure FillArray(const anArray: TIntIntIntArray; aValue: DWord);
>  var
>    x, y: integer;
>  begin
>    for x:=0 to High(anArray) do
>      for y:=0 to High(anArray[x]) do
>        FillDWord(anArray[x][y][0], Length(anArray[x][y]), aValue);
>  end;

Doesn’t iterating the array default the purpose of FillChar? The goal was the most efficient way clear the array with zero’s. Even if the array if nested 3 levels deep (anArray[x][y][z]) it should (I hope) be a contiguous block of memory that was allocated (correct me if I wrong please). 

Regards,
	Ryan Joseph




More information about the fpc-pascal mailing list