Re: Help with NSPointerArray and NSMapTable
Christiaan Hofman <[email protected]>
| Newsgroups | gmane.comp.macosx.devel |
|---|---|
| Message-ID | <[email protected]> |
On Sep 24, 2009, at 16:24, Adam R. Maxwell wrote: > > On Sep 24, 2009, at 2:11 AM, Christiaan Hofman wrote: > >> >> On Sep 24, 2009, at 4:27, Adam R. Maxwell wrote: >> >>> >>> On Sep 21, 2009, at 12:14 PM, Christiaan Hofman wrote: >>> >>>> Apart from this, the 64-bit docs warn against type-casting an >>>> NSInteger as a pointer, but that seems to be exactly what >>>> NSPointerArray expects me to do? If they go against their own >>>> docs I really think they should be more clear. >>> >>> Can you point to where the docs warn against this? >>> >>> thanks, >>> Adam >> >> Right in the Overview of the NSMapTable documentation: >> >> "It can contain arbitrary pointers (its contents are not >> constrained to being objects). > > Oops! I should have been more specific: where do the docs warn > against casting NSInteger to a pointer? I thought that would be > pointer-size on 32 or 64 bit (vs int or long). > It's somewhere in the 64-bit transition docs, <http://developer.apple.com/mac/library/documentation/Darwin/Conceptual/64bitPorting/MakingCode64-BitClean/MakingCode64-BitClean.html >. >> "Note that only the options listed in “NSMapTableOptions” guarantee >> that the rest of the API will work correctly—including copying, >> archiving, and fast enumeration. If you use other >> NSPointerFunctions options, the map table may not work correctly, >> or may not even be initialized correctly." > > Nice. That's the same caveat that an Apple engineer pointed out to > me for CFDictionary (as an excuse for -[NSMutableDictionary > setObject:forKey:] incompatibility with pointer equality > callbacks). Based on that, I'd avoid the NSMapTable class and > either use CFDictionary or the NSMapTable C API. And what are the appropriate callbacks to use for pointers to some kind of struct or float? I tried NSOwnerPointerMapValueCallBacks, but that did not work. I also don't see how the value callbacks can copy the struct or float, because it returns void. Isn't that possible? Christiaan