On 31 Jan 2011, at 09:51, SPUeNTRUP - Kai Henningsen wrote: >> When I was looking at it, I found it hard to see how best to make a fast >> allocation/deallocation scheme thread-safe. > > I learned this from ptmalloc3
ptmalloc() is very heavily optimised for the case in which malloc() and free() are both called in the same thread. For NSEvent, this may well not be the case, as the event is delivered to a run loop, which may pass it off to another thread. Of course, if you want really fast NSEvent allocation and deallocation, then you should take advantage of the fact that NSEvents are inserted at the bottom of the run loop, are immutable, and rarely persist beyond a single run loop iteration. You can then allocate an NSEvent subclass on the stack, inject this, and have its -retain method return a copy of itself on the heap, so you are only calling malloc() at all when someone tries to keep the event beyond the run loop iteration. This would require some tweaking of the current code, I think, because NSEvents are queued by the run loop. Something for Banlu to play with... David -- Send from my Jacquard Loom _______________________________________________ Gnustep-dev mailing list Gnustep-dev@gnu.org http://lists.gnu.org/mailman/listinfo/gnustep-dev