[fpc-pascal] Array clearing

Mattias Gaertner nc-gaertnma at netcologne.de
Thu Apr 13 14:58:11 CEST 2017


On Thu, 13 Apr 2017 19:15:13 +0700
Ryan Joseph <ryan at thealchemistguild.com> wrote:

> > On Apr 13, 2017, at 7:08 PM, Mattias Gaertner <nc-gaertnma at netcologne.de> wrote:
> >   
> >> as I understood from (http://wiki.freepascal.org/Dynamic_array<http://wiki.freepascal.org/Dynamic_array>), SetLength will create a copy of the array and free the memory of the shorter array. In this case, a lot of memory operations and copy operations are performed thus degrading the performances of the code.  
> > 
> > Correct.  
> 
> Why is it copying the array and freeing instead of resizing the existing block (realloc)? That sounds crazy but I don’t know how memory managers work.

It does not free the elements.
It frees the array.

Mattias



More information about the fpc-pascal mailing list