C
copx
How do you implement an event queue in C? The problem I had is that events
needed pointers to the objects they affect and I do not know any way to
check if pointers are actually valid in C. The main issue is that the
objects an event data structure points two might be removed before the event
is executed. The only solution I came up with was scanning the entire queue
each time an object was destroyed to remove all references to it. That was
rather ugly.
Also serializing (i.e. saving to disk) pointer-based structures is horrible
in C. You can not just save/restore pointers instead you have to translate
them to something else. I usually translate them to index values which works
but requires a lot of code (especially if you need to save/restore lots of
pointers who point to data in different data structures).
So what is the elegant way to implement an event queue in C?
needed pointers to the objects they affect and I do not know any way to
check if pointers are actually valid in C. The main issue is that the
objects an event data structure points two might be removed before the event
is executed. The only solution I came up with was scanning the entire queue
each time an object was destroyed to remove all references to it. That was
rather ugly.
Also serializing (i.e. saving to disk) pointer-based structures is horrible
in C. You can not just save/restore pointers instead you have to translate
them to something else. I usually translate them to index values which works
but requires a lot of code (especially if you need to save/restore lots of
pointers who point to data in different data structures).
So what is the elegant way to implement an event queue in C?