On 23 Feb 2009, at 3:36 AM, Adam R. Maxwell wrote: > > On Feb 22, 2009, at 5:16 PM, Christiaan Hofman wrote: > >>> The DictionaryExample.c in /Developer/Examples/CoreFoundation shows >>> how to use a CFDictionary for integers. If you want to make it 64 >>> bit clean, use long/uintptr_t/intptr_t instead of int. For integer >>> arrays or sets, STL is probably a better choice... >>> >> >> The CFDictionary code is very old, and in view of the 64 bit docs >> wrong, so that's not a relevant reference, IMHO. > > Can you be more specific? I use the technique pretty frequently, so > I'd definitely like to know if it's going to break on me! The 64 > bit transition guide says to avoid casting pointers to non-pointer > types, but that's a different problem.
I don't think it can lead to problems in practice, as even on 64 bit a pointer can hold an int or even an NSInteger. But I consider it bad programming. The point is that CF collections use pointers, so you should also pass pointers. When you pass integers or something else there's an implicit cast. >> Using things like >> intptr etc generally I consider hackish, you always have to be very >> careful with sizes. This method is always valid, and is really the >> way >> CF collections are designed. > > Yeah, you have to be careful with sizes, but sizeof(void *) == > sizeof(uintptr_t) == sizeof(long). Since CF collections are > required to work correctly with pointer sizes, I think it will > always be valid to use an equivalent-sized value...unless I miss > something. If you use malloc, you might as well use an NSNumber and > avoid all the CF stuff, since you're taking the performance hit > anyway. It should always be valid, but it's also valid to do all kinds of bad stuff. As for performance, there is a big difference. Here the performance hit is taken only when storing a value, not reading. When you use NSNumber you get it also any time you read. And we're using this specifically for situations that are supposed to be read often and write few (otherwise there wouldn't be a point for these caches in the first place). Except perhaps for BDSKCountedSet. Christiaan ------------------------------------------------------------------------------ Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise -Strategies to boost innovation and cut costs with open source participation -Receive a $600 discount off the registration fee with the source code: SFAD http://p.sf.net/sfu/XcvMzF8H _______________________________________________ Bibdesk-develop mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/bibdesk-develop
