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.

Right now I'm doing this:

int i;
for (i = 0 ; i  < 10 ; i++)
{
NSObject *myObject = [[NSObject alloc] init];
[dictionary setValue:myObject forKey:[NSString stringWithFormat:@"%x", &myObject]];
}

The above does seem to work, but the memory address that I get always seems to be the same.

myObject is a variable (of type pointer) that is allocated on the stack. Its address is always going to be the same inside that tight loop, since the stack pointer isn't changing.

--
Dave Carrigan
[EMAIL PROTECTED]
Seattle, WA, USA

Attachment: PGP.sig
Description: This is a digitally signed message part

_______________________________________________

Cocoa-dev mailing list ([email protected])

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