Re: Why does NSArray count return NSUInteger?
Re: Why does NSArray count return NSUInteger?
- Subject: Re: Why does NSArray count return NSUInteger?
- From: Graham Cox <email@hidden>
- Date: Tue, 31 May 2011 22:13:26 +1000
On 31/05/2011, at 7:36 PM, julius wrote:
>
> On 31 May 2011, at 10:00, Alejandro RodrÃguez wrote:
>
>> It's more than likely that it has to do with the underlying implementation of NSArray which is surely based on C arrays.
>>
>> NSArray is toll-free bridged with CFArray which being part of CoreFoundation is made to work cross-platform and thus should try to be as generic as possible.
Problem is, the first statement I've quoted isn't the case, and the second, while true, is based on CFIndex, not NSUInteger, which is a typedef for signed long. (You can look at the source for CFArray in the Darwin sources: http://www.opensource.apple.com/source/CF/CF-476.15/CFArray.c ).
However I think the historical perspective is helpful - the general principle is to always give yourself the maximum expansion room you can. Note that in the classic Mac OS many data structures were based on shorts, and in quite a few cases later APIs changed these from signed to unsigned to extend the useful capacity of a given structure. These days, the ubiquity of 32 and 64 bits hides the benefit that careful choice of types can give you, which was true until quite recently.
--Graham
_______________________________________________
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