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

2010-04-28 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)?

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

2010-04-28 Thread Henry Vermaak
On 28 April 2010 04:24, Bihar Anwar bihar_an...@rocketmail.com 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()?

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 (ansistring in

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

2010-04-28 Thread Henry Vermaak
On 28 April 2010 05:33, Bihar Anwar bihar_an...@rocketmail.com 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],

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

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 bihar_an...@rocketmail.com 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

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

2010-04-27 Thread Henry Vermaak
On 27 April 2010 14:42, Bihar Anwar bihar_an...@rocketmail.com 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

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

2010-04-27 Thread Bihar Anwar
- Original Message From: Henry Vermaak henry.verm...@gmail.com To: FPC-Pascal users discussions fpc-pascal@lists.freepascal.org 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

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

2010-04-27 Thread Henry Vermaak
On 27 April 2010 18:34, Bihar Anwar bihar_an...@rocketmail.com 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

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

2010-04-27 Thread Bihar Anwar
...@gmail.com To: FPC-Pascal users discussions fpc-pascal@lists.freepascal.org 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 bihar_an...@rocketmail.com wrote: Would Move() be faster, instead of Copy()? I

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 bihar_an...@rocketmail.com 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

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

2010-04-27 Thread Bihar Anwar
(a, 2); - Original Message From: dmitry boyarintsev skalogryz.li...@gmail.com To: FPC-Pascal users discussions fpc-pascal@lists.freepascal.org 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:24 AM