On Jul 28, 2008, at 12:34, Andy Lee wrote:

On Jul 28, 2008, at 2:31 PM, Dave Carrigan wrote:
On Jul 28, 2008, at 11:13 AM, Carter R. Harrison wrote:

If I wanted to store an object in a dictionary and set its key as the object's memory address - how would I go about doing this?

I'm racking my brains trying to think of a good reason to do this and am drawing a blank. I can, however, think of myriad bad reasons.

Count me as another mystified person -- can you say what you're trying to do? I'm thinking maybe some kind of serialization or maybe object caching, but nothing makes sense. It sounds like what you want is a set of objects rather than a dictionary. If you have an address you can just dereference the address -- you don't need to look it up in a dictionary.

I've used this technique when replacing objects in an object graph with different objects. There may be multiple references an "old" object in the graph, and there may be multiple paths through the graph to each reference. When walking the graph, you just use [dict objectForKey: [NSValue valueWithNonretainedObject: oldObject]] to find out if you've already generated a replacement for the old object yet, and use [dict setObject: newObject forKey: [NSValue valueWithNonretainedObject: oldObject] to remember the replacement if you haven't.


_______________________________________________

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]

Reply via email to