Re: NSMapTable with pointer keys ?
Re: NSMapTable with pointer keys ?
- Subject: Re: NSMapTable with pointer keys ?
- From: Guillaume Laurent <email@hidden>
- Date: Thu, 27 Mar 2008 18:14:55 +0100
On Mar 27, 2008, at 17:51 , Benjamin Stiglitz wrote:
[NSMapTable
mapTableWithKeyOptions:NSMapTableObjectPointerPersonality
valueOptions:NSMapTableStrongMemory]
(reading the doc for NSMap, I figured these are the right options)
However, when trying to fetch an object with a void* key to check
for its presence (using the C api as recommended)
NSMapGet(myMap, aKey);
I get an instant crash and looking at the stack trace, it's because
aKey is being sent an ObjC message, to which it will hard time
replying since it's not an NSObject in the first place.
That’s because you’ve marked the keys as being object pointers;
you’ve got your key and value pointer functions reversed.
Just tried, exact same crash. :-(
(Also be sure you want the StrongMemory personality, and not
OpaqueMemory.)
Ah, there seem to be a documentation problem here. The NSMapTable doc
only lists the following personalities as being available :
NSMapTableStrongMemory = 0,
NSMapTableZeroingWeakMemory =
NSPointerFunctionsZeroingWeakMemory,
NSMapTableCopyIn = NSPointerFunctionsCopyIn,
NSMapTableObjectPointerPersonality =
NSPointerFunctionsObjectPointerPersonality
It also says in the overview section that "only the options listed in
“Personality Options” guarantee that the rest of the API will work
correctly". So should I really use NSPointerFunctionsOpaqueMemory
(which has no documentation either except that it's "Available in Mac
OS X v10.5 and later") ?
I suppose OpaqueMemory would fit, though, since what I want is to use
the void* values as index keys, what they are pointing to is
irrelevant at this stage (it's a C++ object).
--
Guillaume
http://telegraph-road.org
_______________________________________________
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