[fpc-pascal] Array clearing

Jürgen Hestermann juergen.hestermann at gmx.de
Tue Apr 4 17:07:30 CEST 2017


Am 2017-04-04 um 15:40 schrieb Ryan Joseph:
 > I’m glad I asked because of arrays of pointers is bad news for performance.

I don't think that you will notice a performance issue with dynamic arrays (though it highly depends on the sizes and levels you use...)

 > Does SetLength on a single level dynamic array not even allocate a continuous block of memory?

Yes, it does (as explained in all the other mails).
A (dynamic) array of integer will be allocated as a single block by SetLength.
So if you only have one level of a dynamic array as in

var MyArray : array of integer;

then SetLength(MyArray,1000) will allocate a single block of 1000 integers.
But with

var MyArray : array of array of integer;

SetLength(MyArray,1000);

will allocate a single block of 1000 pointers (to an array of integer each).
Then, SetLength(MyArray[0],1000) will allocate one (!) block of 1000 integers.
SetLength(MyArray[1],1000) will allocate another block of 1000 integers and so on....




More information about the fpc-pascal mailing list