Re[2]: [fpc-pascal] about dynamic array

2010-05-09 Thread José Mejuto
Hello FPC-Pascal, Sunday, May 9, 2010, 8:04:24 PM, you wrote: s> Sorry to have launched such an argument by starting a new s> thread "about dynamic array". My purpose, as a newcomer discovering s> the world of fpc, was just to get information I could not find s> myself to help me and progress in

Re: [fpc-pascal] about dynamic array

2010-05-09 Thread spir ☣
On Sun, 9 May 2010 16:58:49 +0200 José Mejuto wrote: > So finally we get a common point of view :) Sorry to have launched such an argument by starting a new thread "about dynamic array". My purpose, as a newcomer discovering the world of fpc, was just to get information I could not find myself

Re[8]: [fpc-pascal] about dynamic array

2010-05-09 Thread José Mejuto
Hello FPC-Pascal, Sunday, May 9, 2010, 1:51:20 PM, you wrote: VH> Well, according to this, the dynamic array performs slightly VH> faster in many cases (which is supporting my previously expressed VH> doubts, isn't it?). Of course, with the above-mentioned cost of VH> keeping track of the data st

Re[8]: [fpc-pascal] about dynamic array

2010-05-09 Thread José Mejuto
Hello FPC-Pascal, Sunday, May 9, 2010, 1:40:33 PM, you wrote: >> Thank you, at least one catch my whole idea about when TList can be >> faster that dynamic array or a plain GetMem for the array. VH> Well, you didn't say "can" previously, you said "it is VH> faster". That's quite a difference. Ok

Re: Re[6]: [fpc-pascal] about dynamic array

2010-05-09 Thread Vinzent Höfler
> Hello FPC-Pascal, > > Saturday, May 8, 2010, 4:42:46 PM, you wrote: > > VH> So, apart from a possibly more optimized implementation (like > VH> not changing the allocated memory size on each single > VH> insertion/deletion) how do you come up with the idea that adding > VH> another layer would

Re: Re[6]: [fpc-pascal] about dynamic array

2010-05-09 Thread Vinzent Höfler
> Saturday, May 8, 2010, 5:07:12 PM, you wrote: > > JM> And depending on the usage patterns and the size of the > JM> elements stored in the array, it probably can be. That's all he > JM> was saying, and only as a side remark in the context of the > JM> discussion (which was meanly to steer away a

Re[6]: [fpc-pascal] about dynamic array

2010-05-08 Thread José Mejuto
Hello FPC-Pascal, Saturday, May 8, 2010, 4:42:46 PM, you wrote: VH> So, apart from a possibly more optimized implementation (like VH> not changing the allocated memory size on each single VH> insertion/deletion) how do you come up with the idea that adding VH> another layer would make it faster?

Re[6]: [fpc-pascal] about dynamic array

2010-05-08 Thread José Mejuto
Hello FPC-Pascal, Saturday, May 8, 2010, 5:07:12 PM, you wrote: JM> And depending on the usage patterns and the size of the JM> elements stored in the array, it probably can be. That's all he JM> was saying, and only as a side remark in the context of the JM> discussion (which was meanly to steer

Re: Re[4]: [fpc-pascal] about dynamic array

2010-05-08 Thread Jonas Maebe
On 08 May 2010, at 16:42, Vinzent Höfler wrote: >> 1) >> TheArray: array of ItemArray; >> AnyItem: ItemOfArray; >> [...] >> for j:=0 to 1000 do begin >> SetLength(TheArray,j+1); >> TheArray[j]:=AnyItem; >> end; >> [...] > > About 1000 GetMem operations (and 1000 assignments which aren't ther

Re: Re[4]: [fpc-pascal] about dynamic array

2010-05-08 Thread Vinzent Höfler
> 1) > TheArray: array of ItemArray; > AnyItem: ItemOfArray; > [...] > for j:=0 to 1000 do begin >SetLength(TheArray,j+1); >TheArray[j]:=AnyItem; > end; > [...] About 1000 GetMem operations (and 1000 assignments which aren't there in the code below, so I won't count them). > Now h

Re[4]: [fpc-pascal] about dynamic array

2010-05-08 Thread José Mejuto
Hello FPC-Pascal, Saturday, May 8, 2010, 1:26:09 PM, you wrote: >> But it is faster than inserting elements in a dynamic array (unless >> reference counted ones) because it usually moves less amount of data >> (4/8 bytes per element). VH> Implementing a dynamic array via a list implementation whi

Re: Re[2]: [fpc-pascal] about dynamic array

2010-05-08 Thread Vinzent Höfler
> c> TList wraps TFPList, which is based internally on an array. So access > c> is fast; insertion, deletion not. > > But it is faster than inserting elements in a dynamic array (unless > reference counted ones) because it usually moves less amount of data > (4/8 bytes per element). Implementing

Re: [fpc-pascal] about dynamic array -- p

2010-05-08 Thread Thierry Coq
Denis, you need to get up to speed on , since this is one of the fundamental (and better) differences of pascal. You'll find the typing system actually helps you a lot. FYI, class is one of the possible types. Basically in Pascal, some types are basic: integer, real, some types are structur

Re: [fpc-pascal] about dynamic array

2010-05-07 Thread cobines
2010/5/7 spir ☣ : > I cannot directly "fish" and use the pointer's target. Seems I always need to > pass _via_ the pointer, then all is fine. It's not really annoying. But I > don't understand the difference: in code, both versions are indeed strictly > equivalent. I guess there's an implicit (p

Re: [fpc-pascal] about dynamic array

2010-05-07 Thread Frank Peelo
On 07/05/2010 10:29, spir ☣ wrote: On Fri, 7 May 2010 06:10:30 +0200 cobines wrote: 2010/5/6 spir ☣ : (By the way, started playing with TFPList already, and could not find how to get data back! I mean the symtric of add(). Even tried indexing (who knows, with the syntactic magic of modern

Re: [fpc-pascal] about dynamic array -- p

2010-05-07 Thread spir ☣
On Fri, 7 May 2010 06:10:30 +0200 cobines wrote: PS : I also need the pointer's mediation when a func/proc expects a (typed) element. Must rewrite the code to use an element pointer as parameter (and pass a pointer from the list). This is more annoying since it obscures the func/proc's signat

Re: [fpc-pascal] about dynamic array

2010-05-07 Thread Michael Van Canneyt
On Fri, 7 May 2010, spir ☣ wrote: On Fri, 7 May 2010 06:10:30 +0200 cobines wrote: 2010/5/6 spir ☣ : (By the way, started playing with TFPList already, and could not find how to get data back! I mean the symtric of add(). Even tried indexing (who knows, with the syntactic magic of modern

Re: [fpc-pascal] about dynamic array

2010-05-07 Thread spir ☣
On Fri, 7 May 2010 06:10:30 +0200 cobines wrote: > 2010/5/6 spir ☣ : > > (By the way, started playing with TFPList already, and could not find how > > to get data back! I mean the symtric of add(). Even tried indexing (who > > knows, with the syntactic magic of modern language? ;-).) > > It is

Re: [fpc-pascal] about dynamic array

2010-05-06 Thread cobines
2010/5/6 spir ☣ : > (By the way, started playing with TFPList already, and could not find how to > get data back! I mean the symtric of add(). Even tried indexing (who knows, > with the syntactic magic of modern language? ;-).) It is indexing. var l: TFPList; p: Pointer; index: Integer; b

Re: [fpc-pascal] about dynamic array

2010-05-06 Thread spir ☣
On Thu, 6 May 2010 12:10:39 -0300 Flávio Etrusco wrote: > On Thu, May 6, 2010 at 11:58 AM, Florian Klaempfl > wrote: > > José Mejuto schrieb: > >> Hello FPC-Pascal, > >> > >> Thursday, May 6, 2010, 3:53:59 PM, you wrote: > >> > >> c> TList wraps TFPList, which is based internally on an array. So

Re[2]: [fpc-pascal] about dynamic array

2010-05-06 Thread José Mejuto
Hello FPC-Pascal, Thursday, May 6, 2010, 9:50:34 PM, you wrote: DC> The short answer is because you have not set p2 to nil as you did to p1. I do not want to be rude but, do you read all the message ? I was trying to be ironic, but seems that I was unable maybe due my very limited english, sorry

Re: [fpc-pascal] about dynamic array

2010-05-06 Thread Doug Chamberlin
On 5/6/2010 3:12 PM, José Mejuto wrote: Entering the doom again... Next question could be why: p1: TObject; p2: TObject; p1:=TObject.Create(); p2:=p1; P1.free; p1:=nil; Why I get an AV if accesing p2 ? Because the object has been freed... So why is not p2 = nil as p1 ? The short answer is becau

Re[2]: [fpc-pascal] about dynamic array

2010-05-06 Thread José Mejuto
Hello FPC-Pascal, Thursday, May 6, 2010, 8:58:33 PM, you wrote: >> faster in fact. If the user plans to use a record (which is my >> suspect) with TList he must "new" and "dispose" the elements and he >> will end up with a dyn array of pointers after all, which is a TList. FK> A dyn. array of rec

Re: [fpc-pascal] about dynamic array

2010-05-06 Thread Florian Klaempfl
José Mejuto schrieb: > Hello FPC-Pascal, > > Thursday, May 6, 2010, 4:58:41 PM, you wrote: > >>> c> TList wraps TFPList, which is based internally on an array. So access >>> c> is fast; insertion, deletion not. >>> >>> But it is faster than inserting elements in a dynamic array (unless >>> refere

Re[2]: [fpc-pascal] about dynamic array

2010-05-06 Thread José Mejuto
Hello FPC-Pascal, Thursday, May 6, 2010, 4:58:41 PM, you wrote: >> c> TList wraps TFPList, which is based internally on an array. So access >> c> is fast; insertion, deletion not. >> >> But it is faster than inserting elements in a dynamic array (unless >> reference counted ones) because it usua

Re: [fpc-pascal] about dynamic array -- PS

2010-05-06 Thread Matthias K.
2010/5/6 spir ☣ : > Hello, > > It seems the actual issue with static array is that the size is part the > type. So that one cannot even use a pointer to refer to an array which size > is supposed to change (since the pointer's type itself would be constrained > by the size). Is this correct? > I

Re: [fpc-pascal] about dynamic array

2010-05-06 Thread Flávio Etrusco
On Thu, May 6, 2010 at 11:58 AM, Florian Klaempfl wrote: > José Mejuto schrieb: >> Hello FPC-Pascal, >> >> Thursday, May 6, 2010, 3:53:59 PM, you wrote: >> >> c> TList wraps TFPList, which is based internally on an array. So access >> c> is fast; insertion, deletion not. >> >> But it is faster tha

Re: [fpc-pascal] about dynamic array

2010-05-06 Thread Florian Klaempfl
José Mejuto schrieb: > Hello FPC-Pascal, > > Thursday, May 6, 2010, 3:53:59 PM, you wrote: > > c> TList wraps TFPList, which is based internally on an array. So access > c> is fast; insertion, deletion not. > > But it is faster than inserting elements in a dynamic array (unless > reference count

Re: [fpc-pascal] about dynamic array

2010-05-06 Thread spir ☣
On Thu, 6 May 2010 16:20:58 +0200 José Mejuto wrote: > Hello FPC-Pascal, > > Thursday, May 6, 2010, 3:53:59 PM, you wrote: > > c> TList wraps TFPList, which is based internally on an array. So access > c> is fast; insertion, deletion not. > > But it is faster than inserting elements in a dynam

Re[2]: [fpc-pascal] about dynamic array

2010-05-06 Thread José Mejuto
Hello FPC-Pascal, Thursday, May 6, 2010, 3:53:59 PM, you wrote: c> TList wraps TFPList, which is based internally on an array. So access c> is fast; insertion, deletion not. But it is faster than inserting elements in a dynamic array (unless reference counted ones) because it usually moves less

Re: [fpc-pascal] about dynamic array

2010-05-06 Thread cobines
2010/5/6 spir ☣ : > So, if TList is a type of linked list, it can probably not do the job for me. > Anyway, I'm not a production programmer & would be pleased to explore this > topic as an occasion to learn Pascal and fp further. TList wraps TFPList, which is based internally on an array. So acc

Re: [fpc-pascal] about dynamic array

2010-05-06 Thread spir ☣
On Thu, 6 May 2010 12:16:22 +0200 Graeme Geldenhuys wrote: > 2010/5/6 spir ☣ : > > > > If the answers to last 2 questions is "only every 29th of februar", how can > > one have a "flexible" array? Is there something like that in stock? Would > > you implement it on top of dynamic array, or rathe

Re: [fpc-pascal] about dynamic array -- PS

2010-05-06 Thread Henry Vermaak
2010/5/6 spir ☣ : > Hello, > > If yes, how is it possible to build a "flexible" array type (in which on can > add/remove elements) on top of static array? It depends on what you want to do with the array. As Jonas said, you may want to look at linked lists if you need to add/remove elements freq

Re: [fpc-pascal] about dynamic array

2010-05-06 Thread Graeme Geldenhuys
2010/5/6 spir ☣ : > > If the answers to last 2 questions is "only every 29th of februar", how can > one have a "flexible" array? Is there something like that in stock? Would you > implement it on top of dynamic array, or rather from scratch on top of static > array (since the "dynamicity" does n

[fpc-pascal] about dynamic array -- PS

2010-05-06 Thread spir ☣
Hello, It seems the actual issue with static array is that the size is part the type. So that one cannot even use a pointer to refer to an array which size is supposed to change (since the pointer's type itself would be constrained by the size). Is this correct? If yes, how is it possible to bu

Re: [fpc-pascal] about dynamic array

2010-05-06 Thread Michael Van Canneyt
On Thu, 6 May 2010, spir ☣ wrote: Hello, Where can one find information on types like dynamic array? Also, on funcs or procs that apply on them, like setLength & copy. If the answers to the following questions are somewhere, just tell me... * Can one rely on the fact that setLength keeps

Re: [fpc-pascal] about dynamic array

2010-05-06 Thread Jonas Maebe
On 06 May 2010, at 11:39, spir ☣ wrote: Where can one find information on types like dynamic array? Also, on funcs or procs that apply on them, like setLength & copy. In the documentation: http://www.freepascal.org/docs-html/ref/refsu14.html * Can one rely on the fact that setLength keeps e

[fpc-pascal] about dynamic array

2010-05-06 Thread spir ☣
Hello, Where can one find information on types like dynamic array? Also, on funcs or procs that apply on them, like setLength & copy. If the answers to the following questions are somewhere, just tell me... * Can one rely on the fact that setLength keeps existing data (in the range of the ne