• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSMapTable C function API equivalent
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSMapTable C function API equivalent


  • Subject: NSMapTable C function API equivalent
  • From: George King <email@hidden>
  • Date: Mon, 1 Jun 2009 12:29:10 -0700

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


  • Follow-Ups:
    • Re: NSMapTable C function API equivalent
      • From: Seth Willits <email@hidden>
  • Prev by Date: Fwd: Making an "undefined" Spotlight NSPredicate?
  • Next by Date: Re: NSMapTable C function API equivalent
  • Previous by thread: Fwd: Making an "undefined" Spotlight NSPredicate?
  • Next by thread: Re: NSMapTable C function API equivalent
  • Index(es):
    • Date
    • Thread