Stuff TList, Slices are the shiz!

BlitzMax Forums/BlitzMax Programming/Stuff TList, Slices are the shiz!

Leiden(Posted 2006) [#1]
Just figured out how to use em, way faster than using a TList. Who has been using them all this time and not telling me!?


Dreamora(Posted 2006) [#2]
We all have :-)

But as little warning: Never use slice to raise or lower the size by one. If you do that all the time, the performance will totally break.

As "good optimation" for high speed, double the size if more elements are needed than you have and half the size if you use less than 0.4 * array.length

That way you have some over head (4 bytes per entry so nothing thats actually a problem) but you don't lose any performance for slicing.


H&K(Posted 2006) [#3]
way faster than using a TList

For anyone reading this please let me add, "But only in specific uses"

If you wanted to extend you 1000 Tlist/Slice by one (or Two), then the whole 1000 will be copied over to a new array and then the slice added, whereas with the Tlist only the new element willbe added (and a pointer).

Now maybe what Dream as posted is true, (Ive no reason to doubt Dream, but I wont say it is true), then when you double or half the size of the array, then it doesnt copy the whole array



Leiden(Posted 2006) [#4]
Oh right, So if I want to add just one element to my array (say a TFace or TMesh) then its going to add 1000 of em? Or do you mean Len will still return 2 objects (say if i added 2 TFace's) or 1000 objects?

Argh!?


Mordax_Praetorian(Posted 2006) [#5]
What we mean is that resizing an array using a slice takes a long time (comparatively) for the program to do, and thus you should only resize in chunks to avoid having to do it so often


H&K(Posted 2006) [#6]
Appologies to Dream. Thanks to
Mordeax, I was enlightend to what you meant.

@Leeiden,
What Im saying is that to increase the size of an 1000 array by 1, it takes 1001 copy/Create operations (1000 for the old elements and one for the new element). And to increase a Tlist by 1, it takes 2 Copy/Create operations (One for the element one for the Link).

So if you are piddleing arround with the list/array then it take a lot lot lot longer for arrays.

What dream is saying (I think) is.
If you are going to add 1000 elements to your array/Tlist. It takes 2000 Copy/Create operations for the Array, and for a tList 2000 Copy/Create operation (1000 copy/create for the new elements and 1000 for the Tlink)


slenkar(Posted 2006) [#7]
slices sound good for 3d engine programming,
but tlists have inheritance and methods so they are nice for game programming


Perturbatio(Posted 2006) [#8]
ahem... cough!


Dreamora(Posted 2006) [#9]
and where is the difference to arrays there?
Arrays are in facts objects as well :)


Leiden(Posted 2006) [#10]
So for instance, I'm using an array to hold 100,000 faces, which are never really modified except at creation when the array is filled with faces. In this case, reading back the faces and passing them to the draw function would be faster than a TList right?


H&K(Posted 2006) [#11]
yes


Dreamora(Posted 2006) [#12]
And you would get the significant Pro of beeing able to do indexed access, which is not unimportant with vertices / triangles