Removing first index of an array

  • Thread starter Thread starter ORC
  • Start date Start date
O

ORC

I have a large array where the first index must be removed, but how is the
best way to do that when the application must be optimized to speed?

Thanks
Ole
 
Use ArrayList or any other ICollection to implement your own override for
such class
 
ORC said:
I have a large array where the first index must be removed, but how is the
best way to do that when the application must be optimized to speed?

I would suggest using the Queue class. An actual array would be very
slow as you'd have to copy all the elements each time you removed one -
and ArrayList would work the same way.

If Queue doesn't do exactly what you want, you can use my
RandomAccessQueue from
http://www.pobox.com/~skeet/csharp/miscutil

Basically it's like an ArrayList with a circular buffer.
 
Hi,

An array may not be the best way to store the data if you have this
requirement.
You have two options:
1- Change the store method, using a Queue, an ArrayList or maybe a Stack (
if it's suitable for you )
2- If for some reason you need to use an array what you can do is use a var
to indicate the first index not used, in this way instead of using
array[0] you use array[FirstIndex] and update FirstIndex according.
You can do this a class too.


Cheers,
 
Back
Top