List or Stack on mobile devices?

Monkey Forums/Monkey Programming/List or Stack on mobile devices?

Playniax(Posted 2011) [#1]
Ok, I know about avoiding as many objects on the fly with the new command or removing them from a list ingame but I would like to discuss lists and stacks. How fast are lists or stacks on these mobile devices.? What would you use? If I understand correctly push, pushes a value on the top of the stack causing the other values to move a position down in the stack. Not knowing anything about the internal workings it looks like the longer the stack, the slower the operation. True or false? But adding something to a list with the AddLast method adds the object to the bottom of a list so again without knowing anything about the internal workings logic tells me this is faster in principal. Using the AddFirst for a list suffers from the same problem as the push for stack in that it has to move the other objects down the list. Any thoughts on this?


slenkar(Posted 2011) [#2]
I thought it was the other way around, addfirst and putting something on a stack is faster

JoshK posted on blitzmax.com that he did experiments with this in blitzmax


DGuy(Posted 2011) [#3]
I think it depends most on how you need/want to access your data and which data structure lends itself most naturally to it.

For example, if you need to store an unknown number of elements, and access them repeatedly and sequentally, then use a list.


Jesse(Posted 2011) [#4]
assuming array resizing(slices) work the same way that they work in blitzMax, list will always be faster than stacks.
stacks are single dimension arrays that are resized by moving data from the original data to a new sized array. I believe it is resized every time five more elements are added to the stack so the stack will be slower as the stack becomes larger. list will not get slower or faster but the faster the frequency by which objects are inserted and removed(for either stack or list) will cause the garbage collector to slow down the program.

[edited]
stacks are doubled in size plus 10 elements evertime it's filled. Adding objects might be faster but accessing them it's just as fast. the slowdown comes after filling the array when it has to resize it.

note: stacks are not shrunk only enlarged. objects will remain in the stack even when they are popped until a new item is pushed in to the stack.