|
Because you only want 20ish items then this is better
than a linked list style list because each new node in linked list requires
allocating / freeing memory, which is slower than shuffling a small number of
items over to make room for inserts or cut out deletions.
-----Original Message-----
From: Allan, Samuel Sent: Friday, 7 February 2003 5:08 p.m. To: Multiple recipients of list delphi Subject: RE: RE: RE: [DUG]: Delete a variable from a Dynamic Array So why
not use a static array? I thought that every time you change the size of a
dynamic array it get re-allocated in memory. The whole array then gets copied
from old loc to new loc in memory. This takes time. If you know that you will
only want 20 items max then use a 20 item static array, and keep track of the
last index in an int. Write a bunch of routines to add, browse, delete etc and
encapsulate them in a class. It is now a TStaticArrayList (my name, you can use
it :-) ). This should take all of 30 minutes.
If you
use an array at all and want to maintain order then you will have to copy each
item down into the newly deleted item when you delete.
You
would use a dynamic array if you thought that occasionally you migh need more
than 20 items. So you also keep track of the array's max size. When you run out
of space THEN re-size / re-declare / re-allocate it. A good number is double
it's old size (arbitrary judgement).
-----Original Message-----
From: Jason Coley [mailto:[EMAIL PROTECTED]] Sent: Friday, 7 February 2003 4:54 p.m. To: Multiple recipients of list delphi Subject: RE: RE: [DUG]: Delete a variable from a Dynamic Array I’m only talking about 1 – 20 groups of the same type max, the deletion of a item isn’t a big deal a small section of code to move items down is fine because of the small amount of items. I just thought the dynamic array would be the best way to do what I want, apart from the fact of the corruption that I am getting.
Jay
-----Original
Message-----
Kyley Harris wrote:
It all depends on your access pattern. For simple groups of simple types, or records that you create, pass around a few places, and then discard, a dynamic array is much cheaper - one call to allocate/deallocate lots of entries - rather than lots of individual calls to New and Dispose and/or Create. They're also reference counted for you (copy on write) and Delphi takes care of all the memory management.
If order within the array is important and insertion/deletion in the middle is common (so you can't move a single entry and chop), their performance is O(N) so you're better of with a linked list or similar indirect collection which has OO(log N) or O(1) insert/delete behaviour.
TTFN, Paul.
|
- RE: [DUG]: Delete a variable from a Dynamic... Paul Heinz
- RE: [DUG]: Delete a variable from a Dyn... Kyley Harris
- RE: [DUG]: Delete a variable from a... Paul Heinz
- RE: [DUG]: Delete a variable fr... Kyley Harris
- RE: [DUG]: Delete a variab... Paul Heinz
- [DUG]: window identifi... Alistair George
- RE: RE: [DUG]: Delete a variable from a Dynamic... Jason Coley
- RE: [DUG]: Delete a variable from a Dynamic... Carl Reynolds \(E-mail\)
- RE: [DUG]: Delete a variable from a Dyn... Jason Coley
- RE: RE: RE: [DUG]: Delete a variable from a Dy... Allan, Samuel
- Allan, Samuel
