VBGamer |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Storing objects in memory... Rag on a Stick (14 replies, 0 views) (2000-Dec-30) Ok, probably all games have a similar problem to this, in that you need to store different objects (such as bullets, NPCs, cars etc) in memory, and during the course of the game, the number of these objects is likely to change. So what do you do?
The methods I know of are:
Set a maximum number of objects each with an "Exists" property
Have a collection of objects and use Add and Remove to handle the changing sizes.
Have a dictionary of objects. For this, adding and removing is a bit clumsier than with collections (at least the way I do it :)
A linked list of objects. This would probably be fairly fast especially since most of the time, it is just cycling through each and every object which linked lists are quite good at.
Dynamic array of objects (can't believe I almost forgot this one), similar to the first method except with a dynamic array so there is no maximum objects. This can be slow when resizing the array, so it would probably be best to do it in jumps of 100 objects when resizing and keep the "Exists" property.
So my question is, what do you use, and what do you think would be the fastest method say with the example game being a RTS such as Starcraft and you are keeping track of all the units. So it has to be fast, ugly code is no problem :)
|