Re: [AD] user-defined events

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


On Fri, 2008-10-17 at 00:06 +1100, Peter Wang wrote:
> 
> When is an event supposed to be destroyed?  al_wait_for_event() returns a
> copy of the event, probably on the user's stack.  Allegro doesn't know
> when that copy is no longer needed, so the user needs to explicitly call
> an unref function.

My idea was, Allegro calls the destroy_event() callback whenever it
loses a (not necessarily the last) reference to an event. Because it
calls the copy_event() callback whenever a copy is made, it should be
100% correct - users can do their own reference counting inside the
copy/destroy callbacks, or make actual copies of the user data and free
them. Is it not going to work?

> Implementing reference counting for user events wouldn't actually be
> hard, but I'm still unsure.  If you use atomic instructions then you
> would at least avoid having an extra mutex per event.  Maybe do it as an
> exercise and see?
> 

Yes, likely to call the callbacks at the correct location, it would be
as much effort as implementing reference counting - haven't looked at
the code yet.

> Or use a conservative garbage collector..
> 

I wonder if that would be easy, if I want to only collect my user events
- seems overkill in any case.

-- 
Elias Pschernig <elias@xxxxxxxxxx>





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