Re: [AD] user-defined events

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On 29 Sep 2008, at 08:55, Peter Wang wrote:
The problem is that it's not a deep copy.  Two events can point to the
same user data, e.g. if you register one event source with two queues.
Then the user doesn't know (easily) when the user data can be freed.

No, but the user *should* know when he registers the source with two queues, so he *could* keep track of how often that copy has been received (by adding reference counting to their data structure).

1. You might try to emit an event, but the event source isn't connected to any queues, or all the queues are full. Then the user data needs to
be freed immediately.

Is there a return value that can be checked if emitting an event fails (eg, al_emit_event() returns true or false)? If not, it's probably a good idea to report that information back anyway (even if we will happily ignore it ourselves most of the time).

2. Event queues might be non-empty when they are destroyed so you might
need to free some user data then too.

True. However, can we tell the user to disconnect event sources from the queue, then empty the queue manually and clean up their own custom events? They of course don't need to do that if they don't use any custom events with pointers in them. To make that a bit easier, would it be possible to add a function that pulls the next user event out of the queue? In that case, something like while (event = al_pop_next_user_event(queue)) free_my_custom_event_data(queue);
could work.

Having a cleanup_user_event callback would imply reference counting
again.

True, but I think in this case it's not our problem.

  Can we just say that user events should not contain pointers
to dynamically allocated structures, and if they choose to ignore that
they need to take into account the points above?

We can certainly tell them what the consequences are if they do use them. Basically, we're not responsible for managing their data structures. "Ok, so this is how you use this hole-zapping gun. We use it for walls, but it works on floors too if you point it downwards. If you're not careful you can blow your own foot off though. Just so you know."

Evert




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/