On Fri, Apr 11, 2008 at 6:04 AM, Alastair Houghton <[EMAIL PROTECTED]> 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 (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]