[fpc-pascal] Array clearing
pascaldragon at googlemail.com
Tue Apr 4 16:46:02 CEST 2017
On 04.04.2017 15:40, Ryan Joseph wrote:
>> On Apr 4, 2017, at 7:17 PM, Sven Barth via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
>> If you want continuous memory areas you need to use static arrays or develop your own dynamic data structure that uses array properties.
> I’m glad I asked because of arrays of pointers is bad news for performance. Does SetLength on a single level dynamic array not even allocate a continuous block of memory? I could use GetMem and array[0..0] but it seems like dynamic arrays should do basically that anyways if they’re not nested.
SetLength() allocates a single block of memory, cause array access is
ordinary pointer arithmetic. However if you have an array of array then
the first array stores a pointer to each sub array.
E.g. the following would be valid, too:
=== code begin ===
arr: array of array of Integer;
SetLength(arr, 10, 10);
arr := Nil;
=== code end ===
More information about the fpc-pascal