Re: Storing values in dictionary with their address as the key

2008-07-29 Thread Stuart Rogers
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. Agreed - I can't help

Re: Storing values in dictionary with their address as the key

2008-07-29 Thread Manfred Schwind
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? NSObject *myObject = [[NSObject alloc] init]; [dictionary setValue:myObject forKey:[NSString stringWithFormat:@%x, myObject]]; Just remove the before myObject

Re: Storing values in dictionary with their address as the key

2008-07-29 Thread Nathan Vander Wilt
What about using CFDictionary ? You can create a dicitonary with a callback that support address (NULL for example). I'll echo this; it's a really handy technique that I use frequently (you can even use integers as keys!). WARNING: Just in case, there is a major warning here. You should

Re: Storing values in dictionary with their address as the key

2008-07-29 Thread Nathan Vander Wilt
On Jul 29, 2008, at 8:58 AM, Nathan Vander Wilt wrote: Right, -[NSDictionary setObject:forKey:] on a CFDictionary created with a custom retain callback will invoke copyWithZone: before calling your retain callback. Apple claims this is not a bug. Getting/removing values with

Storing values in dictionary with their address as the key

2008-07-28 Thread Carter R. Harrison
Hey Everybody, 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? Right now I'm doing this: int i; for (i = 0 ; i 10 ; i++) { NSObject *myObject = [[NSObject alloc] init]; [dictionary setValue:myObject

Re: Storing values in dictionary with their address as the key

2008-07-28 Thread Dave Carrigan
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,

Re: Storing values in dictionary with their address as the key

2008-07-28 Thread I. Savant
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. Agreed - I can't help but

Re: Storing values in dictionary with their address as the key

2008-07-28 Thread David Wilson
On Mon, Jul 28, 2008 at 2:13 PM, Carter R. Harrison [EMAIL PROTECTED] wrote: Hey Everybody, 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? Right now I'm doing this: int i; for (i = 0 ; i 10 ; i++) {

Re: Storing values in dictionary with their address as the key

2008-07-28 Thread Quincey Morris
On Jul 28, 2008, at 11:13, 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? The usual way would be to use the result of +[NSValue valueWithNonretainedObject:] as a dictionary key.

Re: Storing values in dictionary with their address as the key

2008-07-28 Thread Jonathan Hess
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

Re: Storing values in dictionary with their address as the key

2008-07-28 Thread Carter R. Harrison
On Jul 28, 2008, at 3:24 PM, David Wilson wrote: On Mon, Jul 28, 2008 at 2:13 PM, Carter R. Harrison [EMAIL PROTECTED] wrote: Hey Everybody, 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? Right now I'm doing

Re: Storing values in dictionary with their address as the key

2008-07-28 Thread Andy Lee
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

Re: Storing values in dictionary with their address as the key

2008-07-28 Thread Charles Srstka
On Jul 28, 2008, at 2:29 PM, Jonathan Hess wrote: 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

Re: Storing values in dictionary with their address as the key

2008-07-28 Thread Andy Lee
On Jul 28, 2008, at 3:29 PM, Jonathan Hess 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

Re: Storing values in dictionary with their address as the key

2008-07-28 Thread Quincey Morris
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

Re: Storing values in dictionary with their address as the key

2008-07-28 Thread David Duncan
On Jul 28, 2008, at 12:32 PM, Carter R. Harrison wrote: The issue was with the format string.. Instead of a %x, I needed a %qx. The %qx displays a 64 bit address whereas the %x displays a 32 bit address. When you give %x, only the least significant 32 bits are printed and those happen to

Re: Storing values in dictionary with their address as the key

2008-07-28 Thread Andy Lee
On Jul 28, 2008, at 3:40 PM, Charles Srstka wrote: On Jul 28, 2008, at 2:29 PM, Jonathan Hess wrote: 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:)

Re: Storing values in dictionary with their address as the key

2008-07-28 Thread Andy Lee
On Jul 28, 2008, at 3:56 PM, Quincey Morris wrote: On Jul 28, 2008, at 12:34, Andy Lee wrote: 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

Re: Storing values in dictionary with their address as the key

2008-07-28 Thread Carter R. Harrison
On Jul 28, 2008, at 3:24 PM, David Wilson wrote: On Mon, Jul 28, 2008 at 2:13 PM, Carter R. Harrison [EMAIL PROTECTED] wrote: Hey Everybody, 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? Right now I'm doing

Re: Storing values in dictionary with their address as the key

2008-07-28 Thread Michael Ash
On Mon, Jul 28, 2008 at 3:29 PM, Jonathan Hess [EMAIL PROTECTED] 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

Re: Storing values in dictionary with their address as the key

2008-07-28 Thread Charles Steinman
--- On Mon, 7/28/08, Carter R. Harrison [EMAIL PROTECTED] wrote: Actually now that I'm looking at this more closely, NSDictionary is expecting an NSString for the key when inserting a value. Your example uses an NSValue for the key - the compiler is throwing a warning for this one..

Re: Storing values in dictionary with their address as the key

2008-07-28 Thread Adam R. Maxwell
On Jul 28, 2008, at 3:23 PM, Jean-Daniel Dupas wrote: Le 29 juil. 08 à 00:09, Charles Steinman a écrit : --- On Mon, 7/28/08, Carter R. Harrison [EMAIL PROTECTED] wrote: Actually now that I'm looking at this more closely, NSDictionary is expecting an NSString for the key when inserting