Re: [fpc-pascal] Array clearing

2017-04-04 Thread Ryan Joseph
> On Apr 4, 2017, at 11:50 PM, Jürgen Hestermann > wrote: > > I am trying to show the memory allocation for the 10x10 array as a "graphic": > > arr --> arr[0],arr[1],arr[2],arr[3],arr[4],arr[5],arr[6],arr[7],arr[8],arr[9] > | | | | |

Re: [fpc-pascal] Array clearing

2017-04-04 Thread Ryan Joseph
> On Apr 4, 2017, at 10:10 PM, Sven Barth via fpc-pascal > wrote: > > While your statement regarding allocation might be true you must not > forget that a dynamic array consists of a meta data block (length, > reference count) that is located directly in front

Re: [fpc-pascal] Array clearing

2017-04-04 Thread Jürgen Hestermann
Am 2017-04-04 um 16:54 schrieb Ryan Joseph: >> var arr : array of array of Integer; >> begin >> SetLength(arr, 10, 10); > “then the first array stores a pointer to each sub array.” > Could you illustrate this is code? > I don’t think I’m understanding this exactly like it’s represented in memory.

Re: [fpc-pascal] Array clearing

2017-04-04 Thread Sven Barth via fpc-pascal
On 04.04.2017 16:27, Ryan Joseph wrote: >>> 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

Re: [fpc-pascal] Array clearing

2017-04-04 Thread Sven Barth via fpc-pascal
On 04.04.2017 16:27, Ryan Joseph wrote: >>> 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

Re: [fpc-pascal] Array clearing

2017-04-04 Thread Mattias Gaertner
On Tue, 4 Apr 2017 16:46:02 +0200 Sven Barth via fpc-pascal wrote: >[...] > SetLength() allocates a single block of memory, To avoid misunderstanding: SetLength(a,dim1,dim2) allocates one block for the dim1 array and then for each element another block. Mattias

Re: [fpc-pascal] Array clearing

2017-04-04 Thread Ryan Joseph
> On Apr 4, 2017, at 10:07 PM, Jürgen Hestermann > wrote: > > 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

Re: [fpc-pascal] Array clearing

2017-04-04 Thread Sven Barth via fpc-pascal
On 04.04.2017 16:54, Ryan Joseph wrote: > >> On Apr 4, 2017, at 9:46 PM, Sven Barth via fpc-pascal >> wrote: >> >> SetLength() allocates a single block of memory, cause array access is >> ordinary pointer arithmetic. However if you have an array of array then >>

Re: [fpc-pascal] Array clearing

2017-04-04 Thread Sven Barth via fpc-pascal
On 04.04.2017 15:40, Ryan Joseph wrote: > >> On Apr 4, 2017, at 7:17 PM, Sven Barth via fpc-pascal >> wrote: >> >> If you want continuous memory areas you need to use static arrays or develop >> your own dynamic data structure that uses array properties. >> >>

Re: [fpc-pascal] Array clearing

2017-04-04 Thread Ryan Joseph
> On Apr 4, 2017, at 9:46 PM, Sven Barth via fpc-pascal > wrote: > > 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

Re: [fpc-pascal] Array clearing

2017-04-04 Thread Sven Barth via fpc-pascal
On 04.04.2017 15:40, Ryan Joseph wrote: > >> On Apr 4, 2017, at 7:17 PM, Sven Barth via fpc-pascal >> wrote: >> >> If you want continuous memory areas you need to use static arrays or develop >> your own dynamic data structure that uses array properties. >> >>

Re: [fpc-pascal] Array clearing

2017-04-04 Thread Jürgen Hestermann
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

Re: [fpc-pascal] Array clearing

2017-04-04 Thread Ryan Joseph
> On Apr 4, 2017, at 7:17 PM, Sven Barth via fpc-pascal > 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

Re: [fpc-pascal] Array clearing

2017-04-04 Thread Jürgen Hestermann
Am 2017-04-04 um 15:18 schrieb Jürgen Hestermann: > var MyArray : array of array of integer; > > you can do: > > SetLength(MyArray,3); > SetLength(MyArray[0],2); > SetLength(MyArray[1],3); > SetLength(MyArray[2],4); > > So MyArray[0] points to an array of 2 integers, > MyArray[1] points to an

Re: [fpc-pascal] Array clearing

2017-04-04 Thread Jürgen Hestermann
Am 2017-04-04 um 13:55 schrieb Ryan Joseph: > Doesn’t iterating the array default the purpose of FillChar? > The goal was the most efficient way clear the array with zero’s. > Even if the array if nested 3 levels deep (anArray[x][y][z]) > it should (I hope) be a contiguous block of memory that

Re: [fpc-pascal] Array clearing

2017-04-04 Thread Sven Barth via fpc-pascal
Am 04.04.2017 13:55 schrieb "Ryan Joseph" : > > > > On Apr 4, 2017, at 4:58 PM, Howard Page-Clark via fpc-pascal < fpc-pascal@lists.freepascal.org> wrote: > > > > You can always use FillChar and its kin on specific 'nested' arrays like this > > > > type > > TIntArray =

Re: [fpc-pascal] Array clearing

2017-04-04 Thread Ryan Joseph
> On Apr 4, 2017, at 4:58 PM, Howard Page-Clark via fpc-pascal > wrote: > > You can always use FillChar and its kin on specific 'nested' arrays like this > > type > TIntArray = array of Integer; > TIntIntArray = array of TIntArray; > TIntIntIntArray = array

Re: [fpc-pascal] Array clearing

2017-04-04 Thread Sven Barth via fpc-pascal
Am 04.04.2017 12:52 schrieb "Mark Morgan Lloyd" < markmll.fpc-pas...@telemetry.co.uk>: > > On 02/04/17 10:00, Jonas Maebe wrote: > >> Allocating new memory via setlength also clears the memory (+ the >> overhead of allocating the memory). > > > Jonas, is it still the case that if SetLength()

Re: [fpc-pascal] Array clearing

2017-04-04 Thread Jürgen Hestermann
Am 2017-04-04 um 12:51 schrieb Mark Morgan Lloyd: > On 02/04/17 10:00, Jonas Maebe wrote: >> Allocating new memory via setlength also clears the memory (+ the >> overhead of allocating the memory). > Jonas, is it still the case that if SetLength() results in existing data being moved that the

Re: [fpc-pascal] Array clearing

2017-04-04 Thread Mark Morgan Lloyd
On 02/04/17 10:00, Jonas Maebe wrote: Allocating new memory via setlength also clears the memory (+ the overhead of allocating the memory). Jonas, is it still the case that if SetLength() results in existing data being moved that the original- which might be e.g. an unencrypted password-

Re: [fpc-pascal] Array clearing

2017-04-04 Thread Howard Page-Clark via fpc-pascal
On 04/04/17 05:25, Ryan Joseph wrote: Is it possible use FillChar on a multidimensional arrays? arr: array of array of array of integer. SetLength(arr, 3, 3, 3); FillChar(arr[0], (3*3*3)*sizeof(integer), false); I’m just getting crashes. You can always use FillChar and its kin on specific

Re: [fpc-pascal] Setting record values

2017-04-04 Thread Sven Barth via fpc-pascal
Am 04.04.2017 05:25 schrieb "Ryan Joseph" : > > Thanks for the tips, I appreciate it. > > This is all pretty trivial but it’s kind of annoying that using an inline class function is more efficient than a constructor despite having identical functionality. It's tempting

Re: [fpc-pascal] Array clearing

2017-04-04 Thread Sven Barth via fpc-pascal
Am 04.04.2017 06:55 schrieb "Ryan Joseph" : > > > > On Apr 2, 2017, at 11:02 PM, Sven Barth via fpc-pascal < fpc-pascal@lists.freepascal.org> wrote: > > > > can be easily seen by looking at the implementation of SetLength() in > > $fpcdir/rtl/inc/dynarr.inc,