[fpc-pascal] Array clearing
pascaldragon at googlemail.com
Sat Apr 1 15:02:41 CEST 2017
Am 01.04.2017 13:31 schrieb "Jürgen Hestermann" <juergen.hestermann at gmx.de>:
> I am wondering what the purpose of filling all
> array elements with zero's could be.
> If I want to discard all elements I would simply delete
> the whole array (setlength(MyArray,0) ).
> But when should it be useful to keep all elements and
> just overwrite them all with zero's (which is also very time consuming)?
> If the exisiting values are no longer valid then why not
> simply delete these elements?
> It's the fastest way to get rid of them.
> If elements were zero before overwriting them with zero's
> I cannot even distinguish between original and overwritten elements.
If you wouldn't change the size of the array then merely doing FillChar (if
not working with managed types) is more performant then freeing the array
and allocating it again (which will also zero out the elements).
Normally the performance difference isn't *that* important, but sometimes
that difference can make or break something.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-pascal