Using List or Map
Monkey Forums/Monkey Programming/Using List or Map
| ||
Friends, I am using List to keep a list of instances of each active object in the game is working perfectly. However, when I delete an object from the list have to use "RemoveEach" and I think that is a little slow. I was thinking of using "MAP" for this kind of thing which would be the most quickly, knowing that I need to quickly delete an instance in the list, what would be the best solution? |
| ||
add a field to the object like below that saves the node of the object when you add it to the list:field node:list.Node<myclass> that field is going to store the exact position where the object is stored in the list when you add a object to the list, assign the node position on the list to the object like this: myobject.node = list.AddLast(myObject) when you need to remove the object from the list, this is all you have to do: myobject.node.Remove() and is faster than using Maps because it directly removes from the list, no searching what soever. [edited] forgot to specify that the class is required in the node declaration |
| ||
Nice solutions! Worked perfectly! Thanks a lot! |