Re: Help with NSPointerArray and NSMapTable

Nat! <nat-wUJ93/3i6JkvAvrZIujWRVaTQe2KTcn/@public.gmane.org>
Newsgroups gmane.comp.macosx.devel
Message-ID <[email protected]>
Am 21.09.2009 um 21:14 schrieb Christiaan Hofman:

>
> On Sep 21, 2009, at 20:54, Nat! wrote:
>
>> I would try NSPointerFunctionsOpaqueMemory (shouldn't retain/ 
>> release or do weird GC stuff on the value),
>> + NSPointerFunctionsIntegerPersonality (use value as hash and  
>> equality) and pass in the integer casted in as void *.
>>
>> If that's right, then I guess the documentation is sufficient ;)
>>
>> Ciao
>>  Nat!
>
> Thanks. The problem I have with the docs is that it is not obvious  
> to me what the "value" is. Is this the pointer itself, or the target  
> of the pointer? If it's the pointer, they should call it the  
> pointer, otherwise they should explain which value they're talking  
> about. For instance, if you are right, than for  
> NSPointerFunctionsIntegerFunctionality the value is the pointer  
> itself (which actually isn't a pointer), while for  
> NSPointerFunctionsStructPersonality, the struct is the target of the  
> pointer. Quite frankly, that distinction is not clear for me by  
> reading the docs.
>

If you look at NSMapTable pre 10.5, there used to be a distinction  
between NSMapTableKeyCallBacks and NSMapTableValueCallBacks, then it  
would have been a little bit clearer what value meant. I'd wager a bet  
that NSPointerFunctionsOptions are just a shortcut to setup the  
callback functions of the NSPointerFunctions that are then really used  
internally, but because of the various memory options it probably got  
tedious to enumerate the various structs.

Anyway with regard to NSPointerFunctionsOptions value only means the  
void *. If you want to use structs as values, you'd need to use  
NSPointerFunctions directly and specify at least the size of your  
struct with the sizeFunction property. And then I'd try  
NSPointerFunctionsMallocMemory + NSPointerFunctionsStructPersonality  
(for a blob of data, like NSRect) with that. (And I am only using  
NSPointerFunctionsMallocMemory because it sounds familiar)

Caveat:this is just from reading the dox and having used NSMapTable  
and friends excessively before.

> 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.
>

I have no opinion on that, I haven't migrated to 64 bit yet :)

Just perusing the documentation, I love it how easy things have become  
with GC. Now we have weak barriers and strong barriers to consider  
instead of retain/release and so much more convenient API to use.  
We're getting really close to Java now. Exciting times.

Ciao
    Nat!
------------------------------------------------------
Thanks for paying my rent. -- EVH
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.