array={1,3,3,6,5}
. Now let's say that I want to a new piece of data to the end of the array for every iteration, but I don't need the data from the beginning.What is the fastest way to do this?
Here are the ideas I have come up with:
array={1,3,3,6,5} while 1 do array[#array+1]=newData end
The problem with this is that I am creating a table that just keeps getting bigger and bigger, and I really don't need all that memory used up.
My next idea was:
array={1,3,3,6,5} i=5 while 1 do array[i+1]=newData array[i-4]=nil i=i+1 end
The problem with this is that I have to keep track of where the data is in the table, which is confusing.
So I then came up with this:
array={1,3,3,6,5} while 1 do for i=1,5,1 do array[i]=array[i+1] end array[5]=newData end
I think that one's the best, but I was wondering if there was a faster way to do it. Because I think with a lot of data, that
for
loop could get pretty slow...If someone could give me some advice I'd appreciate it.