What NSKeyedArchiver probably does is have a dictionary that maps the original 
object pointer values to the copied objects. So instead of just straight-out 
copying an object, it does:

NSString* theKey = [NSString stringWithFormat: @"%p", theOriginal];
id theCopy = [objectCopies objectForKey: theKey];
if( !theCopy )
{
        theCopy = [theOriginal copy];
        [objectCopies setObject: theCopy forKey: theKey];
}

That way, every object only gets copied once, and the copy re-used in other 
spots. That may be part of why it is slower. (NB - you could probably use an 
NSValue +valueWithUnretainedPointer: or whatever as the key, I just quickly 
typed this untested code into the e-mail)

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de

On Feb 14, 2013, at 3:57 AM, Ken Thomases <k...@codeweavers.com> wrote:
> Your question prompted me to try to design an analog of NSKeyedArchiver, 
> NSCode, and NSCoding that would generate the new object graph on the fly as 
> it went instead of producing a data object.  The idea is that the copier (the 
> analog of the archiver/coder) would know which objects had already been 
> copied and so would avoid over-duplicating them in the new graph.  However, 
> that ends up being hard because each object has to copy its related object 
> before it's complete enough to be registered with the copier.  So, it isn't 
> successful in avoiding the potential for infinite recursion.


_______________________________________________

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to