Re: Storing values in dictionary with their address as the key
Re: Storing values in dictionary with their address as the key
- Subject: Re: Storing values in dictionary with their address as the key
- From: "Michael Ash" <email@hidden>
- Date: Mon, 28 Jul 2008 16:51:53 -0400
On Mon, Jul 28, 2008 at 3:29 PM, Jonathan Hess <email@hidden> wrote:
>
> On Jul 28, 2008, at 11:44 AM, I. Savant 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.
>
> A good reason would be that you care about identity equality and not value
> equality. You care that the key is the exact same instance, not that it is
> an equivalent instance. (== vs isEqual:) Another reason would be that the
> keys might not implement NSCopying, which NSDictionary requires.
If NSDictionary and NSSet are too restrictive in terms of how they
manage your objects, use NSMapTable and NSHashTable. On 10.5 they have
a nice object-oriented interface but they still allow the use of
custom callbacks. For example, the
NSPointerFunctionsObjectPointerPersonality constant will cause objects
to be correctly retained and released but will use object identity
rather than equality. NSPointerFunctions can be used to customize it
further.
Mike
_______________________________________________
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