Re: [AD] user-defined events

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


On Mon, 2008-09-29 at 22:55 +1000, 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.
> 
> 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?
> 

Would it be easier having a copy_user_event callback? If users use
dynamically created user events, they would be required to fill in the
copy_user_event callback and deal appropriately with copying (either
also copy their dynamic contents, or do their own reference counting).

In that case, your 1. and 2. above could simply call the
cleanup_user_event callback for all events. And whenever an event is
copied, call the copy_user_event callback. So we do of course get more
complexity again - didn't look enough at the code to know if it
basically would be the same as doing reference counting again.

-- 
Elias Pschernig <elias@xxxxxxxxxx>





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