Arrays are sufficient for ArrayLists? Really??

Timon Gehr timon.gehr at gmx.ch
Mon May 16 11:45:10 PDT 2011


> Thanks for the idea. This seems great, except for a couple of things:
>
> - I _do_ need the order to stay the same, so I can't just put in the last element.
>
> - I only need to remove one element at a time.
>
> - I still don't understand how this helps. Either this modifies the array
directly, in which case
> adding a new element to the array after a removal would still cause a
reallocation every time, or
> this returns a filtered range, in which case it doesn't do what I need (since it
doesn't modify the
> array directly)... am I missing something?

1. Are you sure you need an array rather than a linked list? Removal and insertion
in the middle of the array is very inefficient if you have many elements. (but you
cannot index into a list efficiently, duh)
2. The garbage collector guarantees amortized constant runtime for insertion at
the back of the array.

What exactly do you need the data structure for?

Timon


More information about the Digitalmars-d mailing list