> No, you misunderstand. There is (in the scheme I'm vaguely recalling) > _nothing_ inside the instances > which holds or points to something which holds the retain count. > > There is another data structure entirely which maps from object addresses to > a retain count.
Yes I see, that's also what Jean-Daniel is saying. In which case, my bytewise copy scheme should work, since if a and b are (or derive from) NSObject then if I do this: *b = *a; the retain count of (b) will be unaffected (which is what you want) and remains independent of (a) since retain counts are tied to object addresses, not content. The code I posted before should therefore produce the following results (prediction, untested, fingers crossed): NSObject *a = [[NSObject alloc] init]; printf ("%d\n", [a retainCount]); // 1 NSObject *b = [[[NSObject alloc] init] retain]; printf ("%d\n", [b retainCount]); // 2 *b = *a; printf ("%d\n", [b retainCount]); // 2 [b retain]; printf ("%d\n", [b retainCount]); // 3 printf ("%d\n", [a retainCount]); // 1 I reckon my scheme might actually be faster Ben, if you benchmark it. Without the assert it's just a method call and a memcpy, which the compiler knows the size of and can therefore optimise. Only you can decide whether either approach is worth the risk. Paul 'quick and dirty' Sanders. _______________________________________________ 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 arch...@mail-archive.com