I just read in the NSMapTable Class Reference that I can use the class to map to and from pointers to C structs:

You can configure an NSMapTable instance to operate on arbitrary pointers and not just objects, although typically you are encouraged to use the C function API for void * pointers. The object-based API (such as setObject:forKey:) will not work for non-object pointers without type-casting.

Can somebody point me to the documentation for the "C function API" referred to above? I was hoping to find a CFMapTable but I suppose that would be too obvious :)

Are there any known simple examples of using NSMapTable with C pointers as keys?

As for type casting, does this simply mean that I need to cast my key and value C pointer types to id in order for the compiler to accept them as message arguments?

My particular use case is that I have a simple pair struct that consists of two unsigned ints, which I use as a key to look up an NSArray. I could use a std::map with NSArray* as the value type, and ignore the objective-c retain/release semantics for the NSArray pointers in the map, but I'd prefer to respect those. Currently I'm converting the pair struct into an NSNumber for use as a key in an NSDictionary, which seems to work OK, but I'm concerned that all the autoreleased NSNumbers are going to pile up. Rather than start creating and draining pools, I would prefer to avoid the temporary key instances altogether. This is a performance-sensitive lookup in both time and space; it remains to be seen whether Cocoa hash tables or stl map trees are more efficient.

Thanks!
George
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to