Quote:Original post by virvelvinden
Exactly. But what if I used this approach (with one big object list, make it big so that it never has to change its memory allocations) and only deleted elements in it on special occasions, such as level changes? It would still be possible to add elements to it, as the new elements would go last in the list and wouldn't mess upp the pointers for the objects already in the list.
If you can afford to keep all the objects that are created and destroyed over the course of the level in memory, then this will simplify things by using lazy deletion - instead of destroying objects immediately, you can just mark them as destroyed, to be really cleaned up later.
Quote:Original post by virvelvinden
I should probably point out that the object classes will be really small, which will make the object list stay at a reasonable size.
It still feels a bit risky though, but I think I will give it a shot!
There are definitely risks and costs involved in keeping separate lists, mainly keeping them in sync. There is the cost of updating multiple lists when you modify the database list. There is the risk of other programmers not knowing or remembering to update the index lists or trying to delete objects from index lists (although wrapping up the object management subsystem and lists would prevent this).
Object ownership, management, and updating (and other real-time processing like rendering) has many possible architectural designs. It all depends on your needs and goals. A simple application used only by yourself, which is what I based my suggestions on, should implement a relatively simple solution that is good enough for what you need.
Other goals would require more complex designs. e.g, scalability through multithreading could be better served by multiple lists of objects that can be processed separately; flexibility and modularity could be achieved by breaking objects down into components, then updating components using appropriate subsystems.
You should check out http://gamearchitect.net/. It highlights some issues relevant to this discussion.