Limitless Array

BlitzMax Forums/BlitzMax Beginners Area/Limitless Array

Well the maiin problem of [..200] is that it make a whole new array and copies the old array over to the new array.
So thats quite a big hit if you are resizing arrays all the time.

The reason we sudjested array resizing for this question was that the number of buildings was set once for each game, and so array resizing was the simplest solution. (Well ok, just recrateing the array each time was the simpleist, but you know).

Now if what was wanted was say adding a new unit, or such during game play time, then array resizing might not be the correct way. And possibley TLists would be better. Also it a lot lot easier to remove elements from within a Tlist.

Basicly you use arrays when the siz is going to be basicly static during gamePlay time, and you use Tlist when you want more active control. However its a lot easyer to find say the tenth elemet in an array than a Tlist, so again you need to concider how you are going to use the data.

If you are going to look through the building list (for example), every frame, then you are not looking at the first entry then the second entry, but rather the first entry and then the next entry.

I know this might sound stupid if you are concidering whether to use Tlists or arrays, but often you can use both. That is you have a Tlist and then you have an array with the TLinks in it. (But you only do this when the advatage of using both outwights the disadvantage of using both)

Now TLink is the actual handle for each "element" of the TList, so if for example you do keep them in an array, then you can simply "look" for each member of the list rather than looping though them all.

My advice would be, use arrays right up until you need to use Tlists, then find or write a really good class to handle TLists and then use it from then on [By really good I mean one you understand]. (some people would say that you should put all the objects you create in A Tlist al la B3d, But then you run the Problem in the "How many instances are left", because the Tlist element is always there, so no GC untill you destroy the TLink/element)