Is this a good way to deal with linked lists?

BlitzMax Forums/BlitzMax Programming/Is this a good way to deal with linked lists?

Sonic(Posted 2006) [#1]
I am using a global linked list to hold refs to 'Graphics' (my sprite class).

At the moment, to manage the large amount of sprites I'm using in my game, the only way I can seem to ensure references to them are garbage collected is to make a new linked list, add any Graphics not flagged as 'dead', null the old list, then finally point the global list to the new list.

There appears to be no memory leakage, and it runs perfectly smoothly, so should I just run with it? I seem to have problems with Listremove...


FlameDuck(Posted 2006) [#2]
It depends. From your description, I would have chosen a TMap instead.


Dreamora(Posted 2006) [#3]
There is an easier way.

Whenever you add an object to a TList, you receive a TLink. Save this TLink to your graphics object in some field.

Now when you flag something as dead, just call link.remove() and it is out of the linked list without searching through the list like remove or iterating through the whole list as list.clear(). (remove or "cloning with alive" is nice but takes quite some time that is actually just needed to skip alive /dead data depending on what you do)


Sonic(Posted 2006) [#4]
Thanks for the tips!