Re: faster deep copies?
Re: faster deep copies?
- Subject: Re: faster deep copies?
- From: Uli Kusterer <email@hidden>
- Date: Thu, 14 Feb 2013 15:30:26 +0100
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 <email@hidden> 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 (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