Re: [fpc-pascal] Question about Deleting elements in Dynamic Array

2010-04-28 Thread Bihar Anwar
Thank you very much Henry, David, and Vincent. I think, I must go back to the basic of reference counting. Special thanks to David for the detail explanation. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.o

Re: [fpc-pascal] Question about Deleting elements in Dynamic Array

2010-04-28 Thread Henry Vermaak
On 28 April 2010 05:33, Bihar Anwar wrote: > I've tried to use Move() instead of Copy(). Any objection with the following > code? > > var >  a: array of string; > > SetLength(a, 5); > a[0] := 'aa'; a[1] := 'bb'; a[2] := 'cc'; a[3] := 'dd'; a[4] := 'ee'; > > System.Move(a[3], a[0], 2 * SizeOf(stri

Re: [fpc-pascal] Question about Deleting elements in Dynamic Array

2010-04-28 Thread David Emerson
Vincent Snijders wrote: > Bihar Anwar schreef: > > I've tried to use Move() instead of Copy(). Any objection with the following > > code? > > Yes, at first glance without much thinking, I don't think it is safe. Did you > think through the consequences of copying reference counted types (ansistrin

Re: [fpc-pascal] Question about Deleting elements in Dynamic Array

2010-04-28 Thread Henry Vermaak
On 28 April 2010 04:24, Bihar Anwar wrote: > Ok, I'll try to observe the compiled code using debugger and benchmark it if > needed. BTW, what do you mean by allocating memory directly? Is there another > way to allocate memory for dynamic array besides using SetLength()? I meant using allocmem,

Re: [fpc-pascal] Question about Deleting elements in Dynamic Array

2010-04-27 Thread Vincent Snijders
Bihar Anwar schreef: I've tried to use Move() instead of Copy(). Any objection with the following code? Yes, at first glance without much thinking, I don't think it is safe. Did you think through the consequences of copying reference counted types (ansistring in this case presumably)? v

Re: [fpc-pascal] Question about Deleting elements in Dynamic Array

2010-04-27 Thread Bihar Anwar
) );// instead of a := Copy(a, 3, 2); SetLength(a, 2); - Original Message From: dmitry boyarintsev To: FPC-Pascal users discussions Sent: Wed, April 28, 2010 10:31:09 AM Subject: Re: [fpc-pascal] Question about Deleting elements in Dynamic Array On Wed, Apr 28, 2010 at 7:2

Re: [fpc-pascal] Question about Deleting elements in Dynamic Array

2010-04-27 Thread dmitry boyarintsev
On Wed, Apr 28, 2010 at 7:24 AM, Bihar Anwar wrote: > Ok, I'll try to observe the compiled code using debugger and benchmark it if > needed. BTW, what do you mean by allocating memory directly? Is there another > way to allocate memory for dynamic array besides using SetLength()? Copy() (from t

Re: [fpc-pascal] Question about Deleting elements in Dynamic Array

2010-04-27 Thread Bihar Anwar
users discussions Sent: Wed, April 28, 2010 4:12:26 AM Subject: Re: [fpc-pascal] Question about Deleting elements in Dynamic Array On 27 April 2010 18:34, Bihar Anwar wrote: > > Would Move() be faster, instead of Copy()? I guess so, have you tried to benchmark? If you really need speed, wh

Re: [fpc-pascal] Question about Deleting elements in Dynamic Array

2010-04-27 Thread Henry Vermaak
On 27 April 2010 18:34, Bihar Anwar wrote: > > Would Move() be faster, instead of Copy()? I guess so, have you tried to benchmark? If you really need speed, why don't you allocate the memory directly? Henry ___ fpc-pascal maillist - fpc-pascal@lists

Re: [fpc-pascal] Question about Deleting elements in Dynamic Array

2010-04-27 Thread Bihar Anwar
- Original Message From: Henry Vermaak To: FPC-Pascal users discussions Sent: Tue, April 27, 2010 10:19:45 PM >I think the right way to do this is: >a := copy(a, 3, length(a) - 3); >Presumably copy optimizes this adequately. Henry ___ Would

Re: [fpc-pascal] Question about Deleting elements in Dynamic Array

2010-04-27 Thread Henry Vermaak
On 27 April 2010 14:42, Bihar Anwar wrote: > Just say, I have a dynamic array with size=5, and I want to delete elements > from the index 0 to 2. Is there a trick (the fastest way) to delete those > elements (0 to 2) without moving activities? > > I've tried to make the dynamic array just pointi

Re: [fpc-pascal] Question about Deleting elements in Dynamic Array

2010-04-27 Thread dmitry boyarintsev
On Tue, Apr 27, 2010 at 5:42 PM, Bihar Anwar wrote: > Just say, I have a dynamic array with size=5, and I want to delete elements > from the index 0 to 2. Is there a trick (the fastest way) to delete those > elements (0 to 2) without moving activities? You won't do it faster than this: var  a: