Re: Efficient object wrappers and GC
Re: Efficient object wrappers and GC
- Subject: Re: Efficient object wrappers and GC
- From: "Michael Ash" <email@hidden>
- Date: Fri, 11 Apr 2008 11:07:55 -0400
On Fri, Apr 11, 2008 at 6:04 AM, Alastair Houghton
<email@hidden> wrote:
> Under GC, these kinds of tricks are no longer possible because there is no
> -retain call any more, so no way to tell if it is safe to re-initialise and
> return the same wrapper object.
>
> Aside from re-implementing the data structure itself in ObjC and making all
> of its nodes objects, which might not be possible in some cases, has anyone
> thought of an efficient solution to this problem when running under GC?
The obvious technique would be to stop trying to make the optimization
implicit and to make it explicit and managed by the caller instead. In
other words, you write your API so that it explicitly returns the same
object every time you call -nextObject, just with a new state. Then
you have a copy method which the caller can use to get a new
unchanging object for the case where he wants to keep one around.
Unfortunately questions like "does anyone have a reference to this
object", while answerable, are too expensive to ask on a regular basis
under GC. The GC gets efficiency by asking this question on a bulk
basis once a bunch of objects have built up. Doing it for one object
in a tight loop would completely destroy whatever efficiency you're
gaining, and a whole lot more besides.
Mike
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden