I'd like to have a dictionary using C strings as keys (because I already have const char* strings and would like to spare on creating NSString wrappers) and C structures as values.
I thought using NSMapTable would be a good idea for this. Here is my code: // function for comparing string keys static BOOL MapTableKeyComparator(NSMapTable* table, const void* key1, const void* key2) { int result = strcmp((const char*)key1, (const char*)key2); return result == 0; } NSMapTable* _table; … NSMapTableKeyCallBacks keyCallbacks = NSNonOwnedPointerMapKeyCallBacks; keyCallbacks.isEqual = MapTableKeyComparator; NSMapTableValueCallBacks valueCallbacks = NSNonOwnedPointerMapValueCallBacks; _table = NSCreateMapTable(keyCallbacks, valueCallbacks, 0); … NSMapInsert(_table, name, value); … value = NSMapGet(_table, name); Now, the problem is that sometimes when I try to get a value from the table, the MapTableKeyComparator function is not called at all, and NSMapGet returns NULL, thought immediate dump of the table shows that all previous records are perfectly present in the table. The bug happens sporadically, at different moments. Sometimes it happens at the line of code where it perfectly worked on last debug session. What could be wrong? _______________________________________________ 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com