[fpc-pascal] Array clearing

Ryan Joseph ryan at thealchemistguild.com
Sat Apr 1 05:11:19 CEST 2017

As far as the compiler is concerned what’s the difference between clearing an array using a for-loop vs. FillChar? It seems like iterating the array would be slower but what does FillChar do exactly and is it faster? The primary concern here is that the memory originally allocated (using SetLength right?) remains in the same location.

  list: array of integer;

SetLength(list, 10);

for i := 0 to high(list) do
  list[i] := 0;	

FillChar(list[0], Length(list) * sizeof(integer), 0);

	Ryan Joseph

More information about the fpc-pascal mailing list