Re: [AD] user-defined events

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


On 2008-09-29, Evert Glebbeek <eglebbk@xxxxxxxxxx> wrote:
> 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.

[queues can't be "full" now; I started to reply before that change]

> 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).

Yeah.  Internally we call _al_event_source_needs_to_generate_event().
Maybe something similar should be exposed.

> > 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?

That won't work.  Disconnecting the source from the queue automatically
removes all the source's events from the queue.

> 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.

An al_next_event_from_source() function might be more generally useful.
(And I just *had* to change from linked lists to circular arrays
recently -- removing things from circular arrays is not nice :-P
But it's not a showstopper.)

Peter





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