FROM : Guillaume Laurent
DATE : Thu Mar 27 18:17:18 2008
On Mar 27, 2008, at 17:54 , A.M. wrote:
>
> On Mar 27, 2008, at 11:24 AM, Guillaume Laurent wrote:
>
>> Hi all,
>>
>> I need to build a map of NSObjects indexed by void* pointers.
>> Apparently the right way to do this is to use NSMapTable with the
>> appropriate options :
>>
>> [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.
>>
>> What am I missing here ?
>
> Unless those void pointers are subject to garbage collection,
I hope the void pointers aren't GC'ed - they are pointers to C++
objects, I assume the GC handles C++ objects properly too, that is it
won't try to free them under my feet.
> I think you would have an easier time with NSMutableDictionary and
> [NSValue valueWithPointer:&x] as the key.
Thanks, I'll try that too.
--
Guillaume
http://telegraph-road.org
DATE : Thu Mar 27 18:17:18 2008
On Mar 27, 2008, at 17:54 , A.M. wrote:
>
> On Mar 27, 2008, at 11:24 AM, Guillaume Laurent wrote:
>
>> Hi all,
>>
>> I need to build a map of NSObjects indexed by void* pointers.
>> Apparently the right way to do this is to use NSMapTable with the
>> appropriate options :
>>
>> [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.
>>
>> What am I missing here ?
>
> Unless those void pointers are subject to garbage collection,
I hope the void pointers aren't GC'ed - they are pointers to C++
objects, I assume the GC handles C++ objects properly too, that is it
won't try to free them under my feet.
> I think you would have an easier time with NSMutableDictionary and
> [NSValue valueWithPointer:&x] as the key.
Thanks, I'll try that too.
--
Guillaume
http://telegraph-road.org
| Related mails | Author | Date |
|---|---|---|
| Guillaume Laurent | Mar 27, 16:24 | |
| Benjamin Stiglitz | Mar 27, 17:51 | |
| Guillaume Laurent | Mar 27, 18:14 | |
| Guillaume Laurent | Mar 27, 18:17 | |
| Guillaume Laurent | Mar 28, 00:20 |






Cocoa mail archive

