[crossfire] safe/common item stack/inventory iteration?

Mark Wedel mwedel at sonic.net
Sat Jul 7 18:46:26 CDT 2007


Andreas Kirschbaum wrote:
> Mark Wedel wrote:
>> The only really foolproof way would be to add some flag - something
>> like 'FLAG_NEEDS_TO_BE_DESTROYED'. Instead of the object actually
>> getting destroyed, that flag is set, and then there is some other
>> function later that goes through and cleans these objects up.
>>
>> However, that would add a lot of processing time.
> [...]
>> But because those calls are used everywhere, that cleanup routine
>> would have to examine _all_ of the objects - and lots of other code
>> would have to be modified to be aware of these pending objects (in the
>> for loops above, it would need to skip over these, etc).
> 
> This "huge overhead" can be reduced to a (very small) constant overhead:
> add all objects that get marked with FLAG_NEEDS_TO_BE_DESTROYED to a
> list of objects_to_be_destroyed. After the processing is done (either
> after the loop, or the tick, or periodically after X ticks) actually
> delete all objects from objects_to_be_destroyed. At this time no other
> processing is active, therefore nothing will break.

  But to do that, yet another set of object pointers is needed (or perhaps use 
teh objectlink structure) - you can't use the next/above/below pointers, because 
if you mess with those, you now have a case where the pointers don't point to 
expected data, which is the entire problem we are running into.




More information about the crossfire mailing list