Re: [AD] user-defined events

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


On Monday 29 September 2008, Peter Wang wrote:
> On 2008-09-27, Thomas Fjellstrom <tfjellstrom@xxxxxxxxxx> wrote:
> > On Saturday 27 September 2008, Peter Wang wrote:
> > > On 2008-09-27, Elias Pschernig <elias.pschernig@xxxxxxxxxx> wrote:
> > > > No matter how many fields are added though, it never will be nice.
> > > > How well would using just a single void *data work instead?
> > > >
> > > > It would be allocated whenever an event is emitted - but would it be
> > > > clear to users where to free it? For example, what if the event is
> > > > never received, or what if to event queues are receiving the events?
> > > >
> > > > I think we should make sure the above works, if it does not right
> > > > now. It's the only way I can see this useful - if necessary, we might
> > > > have to provide a callback pointer with a "cleanup_user_event" method
> > > > which is passed the event when it goes out of servrice or something,
> > > > so user code can free the data poiner there. (But maybe that's
> > > > already working.. didn't look too close yet and the example
> > > > apparently just casts an int to a pointer.)
> > >
> > > It doesn't have any support for freeing user data in user events.
> > >
> > > Not sure what to do about it.
> >
> > Little more serious this time, since your new event code will copy events
> > everywhere, shouldn't the user free the event data once they are done
> > with it? Just have to make sure the event queue still doesn't have a
> > handle on it before that.
>
> 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.
>
> And as Elias pointed out:
>
> 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.
>
> 2. Event queues might be non-empty when they are destroyed so you might
> need to free some user data then too.
>
> Having a cleanup_user_event callback would imply reference counting
> again.  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?

I tried not to specify when /exactly/ the user would free the data. Since it 
is user specific, they will need to keep track of it, and be told that 
multiple events may point to the same data. If we can't handle this special 
case in a not too clever manner, we probably shouldn't.

I can see cases where the user is just passing a handle around, and won't 
actually want to free it right away (after getting the initial message). its 
just a convenient way to pass a specific structure to the handler.

Lets try not to think of this data as anything allegro should actually care 
about (It probably shouldn't, it could be anything).

> Peter

-- 
Thomas Fjellstrom
tfjellstrom@xxxxxxxxxx




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